Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: No StringCompare in Mathematica?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67177] Re: [mg67148] No StringCompare in Mathematica?
  • From: gardyloo <gardyloo at mail.wsu.edu>
  • Date: Sun, 11 Jun 2006 02:18:26 -0400 (EDT)
  • References: <200606100854.EAA01451@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi, Steven,

   I knew I'd done this before somehow, and expected to have to wade 
back through a lot of old code to figure out how I'd done it. Turns out 
it was pretty simple. I'm not sure how fast the list sorting is, but 
perhaps this might help:

In[4]:=

list = {"s1", "s3", "s2", "s1", "s5", "s0"}

Out[4]=

{"s1", "s3", "s2", "s1", "s5", "s0"}

In[5]:=

Ordering[list]

Out[5]=

{6, 1, 4, 3, 2, 5}

In[6]:=

list[[Ordering[list]]]

Out[6]=

{"s0", "s1", "s1", "s2", "s3", "s5"}


    You'll find, though, that for sxx with xx>=10, the usual sorting 
mechanism comes into play, and so s15<s2. Kind of annoying, but possible 
to work around, with concomitant slowdowns, of course.

           Hope that helps,
                                Curtis O.

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?
>   


-- 
==========================================================
Curtis Osterhoudt
PGP Key ID: 0x088E6D7A
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================================================



  • Prev by Date: Re: Mathematica doesn't know what it's doing.
  • Next by Date: Reordering limits for Plot3D
  • Previous by thread: No StringCompare in Mathematica?
  • Next by thread: Re: No StringCompare in Mathematica?