> On 30/08/2018 10:24, Keith Clarke via use-livecode wrote:
>> Folks,
>> Is there a single-pass mechanism or more efficient way of returning the 
>> wordOffset of each instance of ?the? in ?the quick brown fox jumped over the 
>> lazy dog? than to use two passes through the text?

Then there is also this repeat-less approach using arrays and filter:

function findWordOffsets pText, pSearchTerm
        put replaceText(pText,"\W+"," ") into pText
        split pText by space
        combine pText with cr and tab
        filter pText with "*" & tab & pSearchTerm
        sort numeric pText
        return pText
end findWordOffsets

put "Then the quick brown fox jumped over "The" very,

very lazy

red dog on the sofa.” into temp       β€” note the extra spaces and line breaks.

put findWordOffsets(temp, β€œthe”)   
returns:
2       the
8       The
15      the

Jim Lambert



_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to