Issues with strpos



Not quite sure what's happening here, the docs for strpos() say:

"Returns the position as an integer. If needle is not found, strpos()
will return boolean FALSE."

Looks fine, I can simply do:

if(strpos("michael", "m")

But then the docs go on to say:

"This function may return Boolean FALSE, but may also return a non-
Boolean value which evaluates to FALSE, such as 0 or "". Please read
the section on Booleans for more information. Use the === operator for
testing the return value of this function."

This seems a little inconsistent to me, means I can't do the
following:

if(strpos("michael", "z") >= 0)
{
//found it!
}

Because that always returns as found, which clearly it isn't. I can
use comparison operators to check for type, but only using "===" or "!
==".

I only want a function to tell me if the string was found (>= 0), I
don't care which position it was etc

What do others use to do this? Preferably without converting to an
array then doing an array find or something.
.



Relevant Pages

  • Re: [PHP] odd behavior of stripos() with === operator *LAST POST*
    ... Regardless of the type, regardless of the species, breed, flavor etc. ... Sure logic dictates that if a return type is confined to the boolean set ... strpos() may return a boolean false or a value from the set of integers - it will never ... scalable system for accessing system services | ...
    (php.general)
  • Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)
    ... >> A packed array of boolean allocates one storage element to each bit. ... >> provided by Ada so that the program will properly represent ... The following example starts with the creation of a generic package ...
    (comp.lang.ada)
  • Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada)
    ... >> A packed array of boolean allocates one storage element to each bit. ... >> provided by Ada so that the program will properly represent ... The following example starts with the creation of a generic package ...
    (comp.lang.cpp)
  • Re: IF/THEN Structure Issues - "Error: Too Many Continuations" PLS
    ... Your boolean array suggestion sounds viable. ... Dim TxtBoxVal As Integer ... >> Else bla bla ...
    (microsoft.public.vb.general.discussion)
  • Re: Bit operations in Ada
    ... I'm new to Ada and bitwise operations is a new challenge in this ... I started with an array of booleans of size 2**n, ... I'm ought to use directly an array of boolean and ... procedure Set (Bit: in Bit_Number; ...
    (comp.lang.ada)