offset broken?

Klaus major-k klaus at major-k.de
Sat Feb 22 13:04:34 EST 2014


Hi Bill,

you have to add the CharsToSkip to the OFFSET by yourself!
See below...

Am 22.02.2014 um 18:49 schrieb prothero at earthednet.org:

> Folks:
> I think there is something weird about "offset". This occurred on version 6.5 and now on 6.6.
>   put "abcdefgabcccablmnopoq" into theChars
>   put offset("c",theChars)
> I get: 3, which is correct
> If I do:
>   put "abcdefgabcccablmnopoq" into theChars
>   put offset("c",theChars,3)
> I get 7.  ??? What the heck? It looks like it returns (the number of characters to the search char) - (# to skip).

7 + 3 = 10, which is correct.

> But, if I do:
>   put "abcdefgabcccablmnopoq" into theChars
>   put offset("c",theChars,7)
> I get: 3

3 + 7 = 10, which is also correct :-)

> So, something is very wrong with the offset command. I worked around this in a parsing script by always not skipping any characters, then after I found the first instance, deleting the characters I wanted to skip before the next offset invocation.
> 
> Seems like a bug to me. What do you think? Or is it only my system? Or is the use of the offset function some convoluted logic that's different from most other implementations of an offset function? What do I know? I'm new to Livecode.

From the docs: about "offset":
...
If you specify how many charsToSkip, the offset function skips the specified number of characters in the stringToSearch. 
The value returned is 
!!!!
relative to this starting point 
!!!
instead of the beginning of the stringToSearch.

> Best,
> Bill

Best

Klaus

--
Klaus Major
http://www.major-k.de
klaus at major-k.de





More information about the use-livecode mailing list