Sort of a problem
Kay C Lan
lan.kc.macmail at gmail.com
Fri May 11 03:27:16 EDT 2012
Because I live in a world of exceptions I thought I'd throw together a
function that allowed the easy integration of them:
First a new List;
Northern Rd
Nth South St
So Ave
Main St
South Rd
Northwest Ct
West East Ave
Oak Ave
East West Ave
N Auburn
W Clinton Blvd
Kimberly Ct
No St
Sth Broadway
S Rector Rd
Maple Ave
S Palin Hwy
W Pine St
Fairmont Ave
And the function:
on mouseUp
local tList
put fld 1 into tList
sort lines of tList by pickStreet(each)
put tList into fld 2
end mouseUp
function pickStreet pName
switch
case ("W Clinton" is in pName)
case ("S Palin" is in pName)
--you get the idea
return pName
break
case (matchText(pName,"[ENSW]\s+(.+)",tNoDirection))
case (matchText(pName,"Nth\s+(.+)",tNoDirection))
case (matchText(pName,"Sth\s+(.+)",tNoDirection))
case (matchText(pName,"East\s+(.+\s.+)",tNoDirection))
case (matchText(pName,"North\s+(.+\s.+)",tNoDirection))
case (matchText(pName,"South\s+(.+\s.+)",tNoDirection))
case (matchText(pName,"West\s+(.+\s.+)",tNoDirection))
return tNoDirection
break
default
return pName
end switch
end pickStreet
HTH
On Fri, May 11, 2012 at 1:13 PM, Jerry Jensen <jhj at jhj.com> wrote:
> Yeah, but it fails if a street is named "SEW Rd" 8)
>
> A better line would be:
> If word 1 of pName is among the words of "N S E W" then
>
> On May 10, 2012, at 9:25 PM, stephen barncard wrote:
>
> > that's the one!
> >
> > On Thu, May 10, 2012 at 9:23 PM, Jerry Jensen <jhj at jhj.com> wrote:
> >
> >> This seems to do the job. No polish, but you'll get the idea.
> >> .Jerry
> >>
> >> Aw, crap, forgot about no attachments. Here's the code:
> >>
> >> ------------------------------------------------
> >>
> >> on mouseUp
> >> local tList
> >> put fld "Streets" into tList
> >> sort lines of tList by pickStreet(each)
> >> put tList into fld "Streets"
> >> end mouseUp
> >>
> >> function pickStreet pName
> >> if word 1 of pName is in "NSEW" then
> >> return word 2 to -1 of pName
> >> else
> >> return pName
> >> end if
> >> end pickStreet
> >>
> >> -----------------------------------------------------
> >>
> >> 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
> >>
> >> _______________________________________________
> >> 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
> >> _______________________________________________
> >> 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
> >>
> >
> >
> >
> > --
> >
> >
> >
> > Stephen Barncard
> > San Francisco Ca. USA
> >
> > more about sqb <http://www.google.com/profiles/sbarncar>
> > _______________________________________________
> > 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
>
>
> _______________________________________________
> 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