Public Function DoesContain(source as string,find as string) as boolean
Dim rg As New RegEx
// need to escape "find" string in some cases
rg.SearchPattern = "["+find+"]"
return (rg.Search(source)<>Nil)
End Function
[quote=338471:@Jean-Yves Pochez]and if this is to parse the sql in your database app, then regex will be mandatory at some time soon…
Instr will never be enough.[/quote]
neither regex or instr is a tokenizer &/or parser which is really the right thing to have to recognize & handle a language
but thats way off this topic
and not to worry, I have previously developed a very fast and very powerful “tokenizer” that I have used not only in Tadpole, but in various interpeter and compiler projects I have worked on over the years… And yes I know there is a difference between a tokenizer and a parser… A tokenizer determines characters that belong to a word, phrase or quoted string, while a parser would determine the meaning or relation of those tokens to an end result
[quote=338461:@Dave S]
Public Function DoesContain(source as string,find as string) as boolean
Dim rg As New RegEx
// need to escape "find" string in some cases
rg.SearchPattern = "["+find+"]"
return (rg.Search(source)<>Nil)
End Function
[/quote]
Seems like a great function, but its returning true for everything I throw at it. Am I not understanding the purpose. I thought it was to see if a string existed inside another. If so return true else false.
No… if you want to find if a string exists inside another string that is what the INSTR function is for…
What I wanted, was to find is ANY one of a series of characters existing in a string"
DoesContain("ABCDEFGHI","ZQIX")=true // BOTH strings contain the letter "I"
to do that with Instr would be
If Instr("ABCDEFGHI","Z")=true or _
Instr("ABCDEFGHI","Q")=true or _
Instr("ABCDEFGHI","I")=true or _
Instr("ABCDEFGHI","X")=true then
[quote=338749:@Dave S]No… if you want to find if a string exists inside another string that is what the INSTR function is for…
What I wanted, was to find is ANY one of a series of characters existing in a string"
DoesContain("ABC","Z")=false
DoesContain("ABCDEFGHI","ZQIX")=true // BOTH strings contain the letter "I"
[/quote]