sorting words ?
Mike Bonner
bonnmike at gmail.com
Wed Dec 9 10:28:05 EST 2015
It seems all you'd have to do is have sort include any trailing chars up to
the next word along with word in question.
" one two three." Spaces to the left of a word (at least as the
first word) don't seem to delimit the word following, hence grabbing word 1
of the above string would return "one" rather than empty. sorting and
returning "one " for one in a sort (and onward) might work, but then as
in my example string, its already a pain again because what do you do with
the preceding spaces?
It seems that if you have special case needs, it'd be easier to roll your
own. (assuming simply setting a delimiter won't work)
Something like this works well..
local sDataArray
on mouseUp
put " the quick brown fox jumped" into tDat
put empty
put 0 into tCount
repeat for each word tWord in tDat
add 1 to tCount
put tWord into sDataArray[tCount]
end repeat
put the keys of sDataArray into tKeys
sort lines of tKeys by wordFunc(each)
put tKeys
end mouseUp
function wordFunc pSortKey
put sDataArray[pSortKey] & comma after msg
return sDataArray[pSortKey]
end wordFunc
You end up with an array with words keyed by their original key position,
plus a key list sorted by word. It leaves the original (strangely
formatted) text alone but you then have easy (and it seems, fast) access to
the words in sorted order.
On Wed, Dec 9, 2015 at 6:17 AM, Mark Waddingham <mark at livecode.com> wrote:
> On 2015-12-09 13:42, jbv at souslelogo.com wrote:
>
>> Hi Mark,
>>
>> I am probably missing something, but items can be separated by multiple
>> itemdelimiters too, but nevertheless the sorting function works, as in
>> this
>> example :
>> get "12,5,,4,10,,,11,24"
>> sort items of it ascending numeric
>>
>> it returns ,,,4,5,10,11,12,24
>> and no compilation error...
>>
>
> Right - but:
>
> "1,2,,,,3,4,5"
>
> Is a list of 8 items - 3 of them empty.
>
> "the quick brown fox jumped"
>
> Is a list of 5 words - multiple item delimiters mean something, multiple
> spaces are just a single 'delimiter' in this context.
>
>
> Warmest Regards,
>
> Mark.
>
>
> --
> Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
> LiveCode: Everyone can create apps
>
> _______________________________________________
> 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