Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a char in a String, multiple times 1

Status
Not open for further replies.

whitshea

Programmer
Sep 16, 2001
7
0
0
US
I am using vbscript to verify an inputted string. This string is 8 chars long. I need to identify if, within the first four characters, a Z or z is present, and if so, I need to return the location of this Z. Any ideas how I can return the location of all the Z's located in the first 4 spaces? I'd like to do this as elegantly as possible. I'm currently using brut force to accomplish this.

Thanks,
Whitney
 
Something like this maybe...

zlocation = instrRev(wholestring,"z",4,vbTextCompare)

This will give you the location of the last "z", case insensitive, within the first four characters.

Or you could use:

zlocation = instr(1,wholestring,"z",vbTextCompare)

And it will give you the first location.
Then maybe:

if zlocation < 4 then
zlocation2 = instr(zlocation,wholestring,&quot;z&quot;,vbTextCompare)
end if

HTH

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top