InStr Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Here's an easy one that I can't see!

Why does

InStr(4,"XXpXXpXXPXXP","P",vbTextCompare)

return 6 and

Instr(5,"ABC-123-XYZ","-",vbTextCompare)

return 8??? I thought the second one would return 4 because the second dash
is the fourth character when you start search at position 5.

THANKS!
 
InStr return the Absolute Position in the string, regardless of the
"Start position" the Start position just tells it to skip the first few
characters.

Charles
 
It returns the position from the start of the string, not relative to where
you start searching.
 
Because it returns its position in the string, not relative to the start
point.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Instr return the position of the character from the beginning of the string,
not relative to where you start.

NickHK
 
Aren't they doing it exactly the same way. Returning the position of the
character in that string--no matter where you started.

It's not where you start the search, the function is returning the position in
the string.
 
Tom,

But why does the first example return 6 for the "P" when it is actually the
9th character? I must REALLY be missing something!

Norm
 
Sorry for being so blind today! I was expecting it to find the capital P.

I think I'll go crawl under a rock now!
 
Norm said:
Tom,

But why does the first example return 6 for the "P" when it is actually the
9th character? I must REALLY be missing something!

Norm

Two things: InStr is maybe(?) NOT case-sensitive but DOES only begin to
look where you tell it to... AND returns position from beginning of
string (as prev. stated).

Will
 
Back
Top