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

using a charlist with instr 2

Status
Not open for further replies.

JesOakley

Programmer
Jan 21, 2008
42
0
0
GB
To be honest, I can't believe I've not been able to find the answer to this question either in Tek-Tips or on the net, but I can't, so I am looking for the Tek-Tips experts to put me straight!
I simply want to find out if a string contains any of some specified characters. I have tried
Code:
If InStr(1, strWholeRec, "[!0-9. ]", vbBinaryCompare) <> 0 Then
against a data-line of "82103 100j000000002" expecting the lowercase 'j' to trigger the If, but it isn't doing so.
Can anyone advise on how to achieve this?
Thanks in advance
 
Use the Like operator:
If strWholeRec Like "*[!0-9. ]*" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You may find regular expressions useful if your lines get any more complicated. Here are a few notes on RegEx.

Code:
'[URL unfurl="true"]http://msdn.microsoft.com/en-us/library/ms974570.aspx[/URL]
Dim objRegEx As RegExp
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.IgnoreCase = True
objRegEx.Global = True

'This is a sample string, the line would go here
strText = "q@12""£c" 

'Find anything not a-z, 0-9
objRegEx.Pattern = "[^a-z0-9]"

'Replace with a dash, "" is fine too. 
strOut = objRegEx.Replace(strText, "-")

 
Thank you PHV. Absolutely pin-pointed the solution and extremely quickly (unlike this response - doh).
And thanks Remou too; I shall investigate regular expressions too.
Both
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top