Sort of a problem
Bob Sneidar
bobs at twft.com
Fri May 11 11:56:17 EDT 2012
Loop through each line putting the actual street name in item 2, sort by item 2 of each, loop through and delete item 2 of every line. Bit clunky, but effective. Another way would be to have a function and sort by the returned value of the function. Not sure that is possible but I think I saw that done somewhere.
Bob
On May 10, 2012, at 8:46 PM, Jim Hurley wrote:
> I have a list of streets:
>
> Main St
> Oak Ave
> N Auburn
> Kimberly Ct
> S Rector Rd
> Maple Ave
> W Pine St
> Fairmont Ave
>
> I want to sort them, but ignoring the compass prefix (N E S W) to give:
>
> N Auburn
> Fairmont Ave
> Kimberly Ct
> Main St
> Maple Ave
> Oak Ave
> W Pine St
> S Rector Rd
>
> The best I have come up with is performing a bubble sort where I have control of the first word.
>
> That script is below. This works well enough for short lists, but not for longer lists.
> It might be possible to speed it up with arrays, but that is not what I'm after right now.
> I have seen some amazing things done with custom sorts in Live Code. I confess, I never understood them.
>
> Is there a custom sort available in Live Code to do this kind of sort?
>
> Thanks,
> JIm Hurley
>
> Here is the bubble sort:
>
> on mouseUp
> put field 1 into tList
> put "N E S W" into tWordsToIgnore
> put the number of lines in tList into n
> repeat
> put true into noChange
> repeat with i = 1 to n-1
> put theFirstWord(line i of tList, tWordsToIgnore) into tFirst
> put theFirstWord(line i + 1 of tList, tWordsToIgnore) into tSecond
> --Reverse sequencial pairs if out of order.
> if tFirst > tSecond then
> put line i of tList into temp
> put line i + 1 of tList into line i of tList
> put temp into line i + 1 of tList
> put false into noChange
> end if
> end repeat
> if the shiftKey is down then exit to top --Just in case
> if noChange then exit repeat ---Keep it up until no change.
> end repeat
> put tList into field 2
> end mouseUp
>
> function theFirstWord temp, tIgnoreWords
> put word 1 of temp into tFIrstWord
> if tFirstWord is among the words of tIgnoreWords then
> return word 2 of temp
> else
> return word 1 of temp
> end if
> end theFirstWord
> _______________________________________________
> 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