StrataFrame Forum

String Comparison

http://forum.strataframe.net/Topic7271.aspx

By Ben Kim - 3/2/2007

Hello all,

The language we are converting from had a handle function we could call that would do string comparisons.  For example:

If InString("DEF", "ABCDEFXYZ", 1, 1)
   ...Do something - return value was 3 (found at character position 3)
Else
   ...Comparison failed
End

Params for INSTRING(SubString, String, (optional Step), (optional Start))
SubString - A string constant, variable or expression that contains the string for which to search

String - A string constant or variable to be searched

Step - An optional numeric constant, variable or expression which specifies the step length of the search.  A step of 1 would search for the substring at every character in string, 2 starts at every other character. A negative step value of -1 will search from right to left within the string.  If omitted, step is defaulted to the length of the substring

Start - An optional numeric constant, variable or expression which specifies where to begin the search of the string.  If omitted it is defaulted to 1.

I have looked at the String Comparison method of the String type and it does not seem to fit the bill.  Before coding this function myself, does anyone know of any other built-in methods that would work just like the Clarion InString function? Or offer a code snippet?

Thanks!

Ben

By Greg McGuffey - 3/2/2007

Ben,



Check out String.IndexOf. I.e. "abcdef".IndexOf("def") = 3


By Ben Kim - 3/2/2007

Thanks Greg.  This should work out find with the exception of reverse searching which I do not believe we used anyway in the legacy code.

Ben