View Full Version : Where be Strpos or it's equiv?

07-04-2008, 12:21 PM
trying to do a simple test script here.
All I want it to check a string for the existence of a substring a la c++ strpos()
or strings mystr.pos() type action.

As far as I can tell from the docs I have (old I grant), there doesn't seem to be any sort of strpos() facility in LScript.

What I am after is checking a line of text conforms to what I expect.

07-04-2008, 06:12 PM
Well, you can use

if (expectedstring==inputstring) then etc

Or if you just want to see if a string is contained in another

if(input.contains(expectedstring) then etc

Or if you're looking for it in a certain place
if(strleft(input,5)==expected) then
if(strright(input,5)==expected) then
if(strsub(input,3,4)==expected) then


07-05-2008, 12:41 AM
that link is extremely helpful thanks Mike.

07-05-2008, 05:32 AM
Ahh, 'contains' - so similar to C# in that respect - Ta Mike! :)
Odd that the reference manual doesn't list that though.

07-05-2008, 05:38 AM
The problem arises where I don't know for sure where in the string a character may be,
so having determined it does exist, I still need to find it's position. As contains doesn't return posn if it exists, simply if it does exist, whereas in C# it returns -1 if not exist, otherwise it's actual start pos.
Or is this a case of having to write ones own 'strpos' action via basic string parse by char?
Aww feck - ignore me... just found it - DOH!
"IndexOf" (also in C#).

>>Slaps forehead and goes to make some coffee..which I obviously need!<<