Re: String comparison
- To: mathgroup at smc.vnet.net
- Subject: [mg55052] Re: String comparison
- From: "Valeri Astanoff" <astanoff at yahoo.fr>
- Date: Thu, 10 Mar 2005 05:25:19 -0500 (EST)
- References: <d0mo83$755$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
My solution : In[1]:= LT[a_String /; StringLength[a] >= 1, b_String /; StringLength[b] >= 1]:= LT[StringTake[a,1], StringTake[b,1]] /; Not[StringLength[a] == 1 || StringLength[b] == 1]&& Not[StringTake[a,1] == StringTake[b,1]]; LT[a_String /; StringLength[a] >= 1, b_String /; StringLength[b] >= 1]:= LT[StringDrop[a,1], StringDrop[b,1]] /; Not[StringLength[a] == 1 || StringLength[b] == 1]&& StringTake[a,1] == StringTake[b,1]; LT[a_String /; StringLength[a] == 1, b_String /; StringLength[b] > 1]:= First@ToCharacterCode[a] <= First@ToCharacterCode[b]; LT[a_String /; StringLength[a] >= 1 , b_String /; StringLength[b] == 1]:= If[First@ToCharacterCode[a] < First@ToCharacterCode[b],True,False]; LE[a_String /; StringLength[a] >= 1 , b_String /; StringLength[b] >= 1]:= LT[a,b] || a == b; GT[a_String /; StringLength[a] >= 1, b_String /; StringLength[b] >= 1] := !LE[a,b]; GE[a_String /; StringLength[a] >= 1, b_String /; StringLength[b] >= 1] := !LT[a,b]; In[8]:= alist={{a,3,"bca"},{b,1,"cba"},{c,2,"abc"}}; In[9]:= Sort[alist,#1[[3]]~LT~#2[[3]]&] Out[9]= {{c,2,abc},{a,3,bca},{b,1,cba}} hth v.a.