Find vs. Offset
Peter M. Brigham
pmbrig at gmail.com
Fri Dec 28 14:22:17 EST 2012
Thank you kindly. Mind you, it didn't start off clean. But that's the nice thing about LC, it's so easy to clean things up after the basic problem is solved.
-- Peter
Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig
On Dec 28, 2012, at 1:18 PM, Geoff Canyon wrote:
> I'm a big advocate of clean functions, and I just want to point out that
> this is really nicely done: clear, compact, efficient, documented, and the
> function name itself perfectly describes what it does.
>
> Really nice!
>
> On Wed, Dec 19, 2012 at 4:33 PM, Peter M. Brigham <pmbrig at gmail.com> wrote:
>
>> function offsets str,container,includeOverlaps
>> -- returns a comma-delimited list of all the offsets of str in container
>> -- 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
>> -- returns 0 if str is not in container
>> 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
>>
>>
> _______________________________________________
> 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