offset broken?
Peter M. Brigham
pmbrig at gmail.com
Sun Feb 23 07:17:16 EST 2014
Here's a useful function that demonstrates the use of the third parameter for offset(). It returns all the offsets of a string in a container:
function offsets str,container,includeOverlaps
-- returns a comma-delimited list of all the offsets of str in container
-- returns 0 if not found
-- third param is optional:
-- offsets("xx","xxxxxx") returns "1,3,5" not "1,2,3,4,5"
-- ie, by default, overlapping offsets are not counted
-- if you want overlapping offsets then pass "true" in 3rd param
-- note: to get the last offset, use "item -1 of offsets(...)"
if str is not in container then return 0
if includeOverlaps = empty then put false into includeOverlaps
put empty into offsetList
put 0 into startPoint
repeat
put offset(str,container,startPoint) into thisOffset
if thisOffset = 0 then exit repeat
add thisOffset to startPoint
put startPoint & comma after offsetList
if not includeOverlaps then
add length(str)-1 to startPoint
end if
end repeat
return item 1 to -1 of offsetList -- delete trailing comma
end offsets
-- Peter
Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig
On Feb 22, 2014, at 2:38 PM, Richmond wrote:
> On 22/02/14 21:35, Richmond wrote:
>> Sorry: Neanderthal question time:
>>
>> I cannot see anything about charsToSkip in the inbuilt (i.e. in the IDE) documentation (6.6. dp1).
>>
>> Went round in circles on the website.
>>
>> ---------------------
>>
>> Anyway:
>>
>> I set up a boring little stack with a fld "fORIGIN" conatinong "The quick brown fox jumps over the lazy dog"
>>
>> and that was jolly nice,
>>
>> then I set up another fld called "fREZ"
>>
>> and a button with this script:
>>
>> on mouseUp
>> put empty into fld "fREZ"
>> put fld "fORIGIN" into ORIGIN
>> put offset("o",ORIGIN) & ", " after fld "fREZ"
>> put offset("o",ORIGIN) & ", " after fld "fREZ"
>> put offset("o",ORIGIN) & ", " after fld "fREZ"
>> end mouseUp
>>
>>
>> in the hope I would get something like "13, 18, 27," in fld "fREZ"
>>
>> but all I got was "13, 13, 13"
>>
>> so I really cannot see what the utility of 'offset' is at all.
>>
>> ---------------------------------
>>
>> I made another button with this script:
>>
>> on mouseUp
>> put empty into fld "fREZ"
>> put 1 into INDEKS
>> repeat until char INDEKS of fld "fORIGIN" is empty
>> if char INDEKS of fld "fORIGIN" is "o" then
>> put INDEKS & ", " after fld "fREZ"
>> else
>> --do nix
>> end if
>> put (INDEKS + 1) into INDEKS
>> end repeat
>> end mouseUp
>>
>>
>> and that returned "13, 18, 27, 42"
>>
>> a whole lot more useful.
>>
>> -----------------------------------
>>
>> Richmond.
>
> Sorry about the previous post: trembly fingers on the PASTE button :P
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list