Great Tip from Ken Ray about lineOffset
Chipp Walters
chipp at chipp.com
Fri Mar 25 02:44:33 EST 2005
Chatting w/ Ken Ray tonight, he shared a really cool tip...one I didn't
know.
The lineOffset function returns the line number of the first occurence
of a matching string.
So if you have a list tList:
A,apple
B,bacon
C,carrot
And you use
put lineOffset("C",tList)
it will return '2' because 'c' is in 'bacon' and that's on line 2.
Of course what we want is to find the first occurence of a line STARTING
with 'C'. Many of you know that lineOffset doesn't work with regular
expressions.
So doing something like:
put lineOffset("C*",tList) won't work.
But, it turns out this will do the job!
put lineOffset(cr & "C",cr & tList)
The first cr makes sure the line you're looking for starts with 'C' and
the second one is used to 'sync' up the number you're returning.
Thanks Ken!
More information about the use-livecode
mailing list