Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Idl-pvware > Re: sorting the...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 7 Topic 5415 of 6248
Post > Topic >>

Re: sorting the chars in a string

by Spon <christoph.blau@[EMAIL PROTECTED] > Feb 11, 2008 at 08:23 AM

elwood wrote:
> Excellent!
> Thank you!
> A minor variation on the below-
> what if I want to split a string into a string array in which each
> element is one character?
> I think I can figure out a lengthy way to do it if I first convert the
> string to byte.
> BUT
> strjoin will knit a string array back together, but is there a way to
> use strsplit to rip off each char,
> one by one and put them into a string array?
> Something like the following perhaps;
> x="abdcf"
> arrayofchars=strsplit(x,'.',/regex,/extract)
>
> -the above doesnt work, it returns an empty string :-(

 new_string_array = string(transpose(tmp[sort_inds]))

>
> On Feb 11, 9:02 am, Lasse Clausen <la...@[EMAIL PROTECTED]
> wrote:
> > On 11 Feb, 15:39, elwood <epolo...@[EMAIL PROTECTED]
> wrote:
> >
> > > I've been trying to think of a simple way to alphabetically sort an
> > > individual string
> >
> > > Say I have the string x="abdcf"
> > > Is there a way to sort it and return a new string which is in
correct
> > > alphabetical order,
> > > and/or reverse alphabetical order.
> >
> > > Maybe its obvious, but I havent worked with strings too much in IDL
> > > and I cant seem to find
> > > a way to do this (strsplit and stregex somehow??)
> >
> > > Thanks,
> > > Elisha
> >
> > Hi there,
> >
> > convert the string to an array of bytes, like so
> >
> > test = 'sfbvvaedfvtrgvsdvrbnyhtfc'
> > tmp = byte(test)
> >
> > This conversion happens according to the ASCII table, if I am not
> > mistanken, which connects a number to a character in ascending order,
> > on my machine a = 97, b = 98 and so on. Then sort that byte array and
> > build up the string again.
> >
> > sort_inds = sort(tmp)
> > new_string = string(tmp[sort_inds])
> > print, new_string
> >
> > That works, use REVERSE() if you want the sorting done from z-a.
> >
> > Cheers
> > Lasse Clausen
 




 7 Posts in Topic:
sorting the chars in a string
elwood <epolomsk@[EMAI  2008-02-11 06:39:53 
Re: sorting the chars in a string
Lasse Clausen <lasse@[  2008-02-11 07:02:34 
Re: sorting the chars in a string
elwood <epolomsk@[EMAI  2008-02-11 07:36:17 
Re: sorting the chars in a string
=?ISO-8859-2?Q?F=D6LDY_La  2008-02-11 16:37:13 
Re: sorting the chars in a string
elwood <epolomsk@[EMAI  2008-02-11 07:42:06 
Re: sorting the chars in a string
elwood <epolomsk@[EMAI  2008-02-11 07:36:32 
Re: sorting the chars in a string
Spon <christoph.blau@[  2008-02-11 08:23:34 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 14:38:36 CDT 2008.