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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Position of Mutilple Characters search in a text string (97) 1

Status
Not open for further replies.

jw45

Programmer
May 27, 2005
56
US
I need a way to find the first occurrence of any of the following characters that appear in a string starting in position 3 and return the position.

Characters to find: _ / - * {space} '

I know I can do it with nested if's and instr but believe there has to be a slicker way.

Can anyone help?

I'm using Access 97.
 
Typed, not tested:
iPos = 0
For Each x In Array("_", "/", "-", "*", " ", "'")
i = InStr(3, yourString, x)
If i > 0 And i < iPos Then iPos = i
Next
MsgBox "Position = " & iPos


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Thanks. Worked great with a minor modification. Had to remove the AND statement. Also, added an exit to the loop.
Code:
iPos = 0
For Each x In Array("_", "/", "-", "*", " ", "'")
  I = InStr(3, yourString, x)
  If I > 0 [s]And I < iPos[/s] Then iPos = I: GoTo Cont:    
Next

Cont:
MsgBox "Position = " & iPos

Another * for you!
Thanks,
JW
 
Try this instead:
iPos = 1 + Len(yourString)
For Each x In Array("_", "/", "-", "*", " ", "'")
i = InStr(3, yourString, x)
If i > 0 And i < iPos Then iPos = i
Next
MsgBox "Position = " & iPos

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top