Re: No StringCompare in Mathematica?

• To: mathgroup at smc.vnet.net
• Subject: [mg67170] Re: No StringCompare in Mathematica?
• Date: Sun, 11 Jun 2006 02:17:59 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On 6/10/06 at 4:54 AM, hattons at globalsymmetry.com (Steven T. Hatton)
wrote:

>I wanted to sort a list of XMLElements based on the text in the
>third descendent of the element type used to form the list.  In
>order to set up the comparison predicate, I had to(?) form a list of
>the two candidate strings and compare it to the sorted version of
>itself.  The sort was fairly slow in executing.  I would like to
>have simply done s1 < s2, but Mathematica doesn't appear to support
>that.  Is there a way to get that functionality more simply than
>what I described?

I probably don't understand well enough what you are trying to do. But it seems to me Sort or Ordering will do what you need without any additional functions. That is,

First generate some random strings

In[5]:=
data=Table[StringJoin@@(FromCharacterCode/@Table[Random[Integer,{97,122}],{5}]),{10}]

Out[5]=
{vfihk,asqhf,dhtal,nwcsh,junme,sbbfn,zzpcd,xlfdv,eewgm,fcwjj}

and Sort works fine

In[6]:=
Sort[data]

Out[6]=
{asqhf,dhtal,eewgm,fcwjj,junme,nwcsh,sbbfn,vfihk,xlfdv,zzpcd}

and if this were the middle element of three you could use Ordering, i.e.

data[[Ordering[data[[All,2]]]]]

should work since

In[7]:=
Ordering[data]

Out[7]=
{2,3,9,10,5,4,6,1,8,7}

seems to work fine.

But if you did need to directly compare two strings, then it seems

In[9]:=
OrderedQ[{Last@data,First@data}]

Out[9]=
True

would do what you want.
--
To reply via email subtract one hundred and four

```

• Prev by Date: Re: Llearning Mathematica
• Next by Date: structure array equivalent in Mathematica
• Previous by thread: Re: No StringCompare in Mathematica?
• Next by thread: List Comparison