[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string to array conversion





David Fanning wrote:
> 
> Karsten Schmidt (k.schmidt@vermes.fh-oldenburg.de) writes:
> 
> > Hi Alex, thanks for your answer,
> > I want to change the stringlength or produce new strings (delete and add
> > some words), example:

Dear Karsten,


this is our solution of a replace_string routine.


For further routines copyright and licence. 
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.html

The routine itselfs.
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_source/idl_html/dbase/download/replace_string.tar.gz

The routine as loadable module.
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_source/idl_html/dbase/download/replace_string.sav


; EXAMPLE:
;   help,replace_string('Dies ist ein Test',' ','_')
;   <Expression>    STRING    = 'Dies_ist_ein_Test'
;   help,replace_string('Dies ist ein Test',' ','_',pos=5)
;   <Expression>    STRING    = 'Dies ist_ein_Test'
;   help,replace_string('Dies ist ein Test',' ','_',pos=5,no=1)
;   <Expression>    STRING    = 'Dies ist_ein Test'
;   help,replace_string('Dies ist ein Test','ist','ist')
;   <Expression>    STRING    = 'Dies ist ein Test'
;   help,replace_string('Dies ist ein Test, ist ein','ist','ist nicht')
;   <Expression>    STRING    = 'Dies ist nicht ein Test, ist nicht ein'
;   help,replace_string('\\\\\\\\\','\','/')
;   <Expression>    STRING    = '/////////'
;  
help,replace_string('["..\idl_html\idl_work_cat.htm"]','cat','cat_org')
;   <Expression>    STRING    = '["..\idl_html\idl_work_cat_org.htm"]'
;   print,replace_string(['12:33:00','12:33:00','12:33:00'],':','')
;   123300 123300 123300
;  
print,replace_string(['12:33:00','12:33:00','12:33:00'],':','',pos=5)
;   12:3300 12:3300 12:3300
;   print,replace_string( 'asdf___ertz_j','__', '')
;   asdf_ertz_j
;  
print,replace_string(['12:33:00','12:33:00','12:33:00'],':','',pos=5,count=c),c
;   12:3300 12:3300 12:3300
;   3
;  
print,replace_string(['12:33:00','12:33:00','12:33:00'],':','',count=c),c
;   123300 123300 123300
;   6

> >
> > a=string('llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll')
> >
> > print,strlen(a)
> >          272
> > help,a
> > A               STRING    =
> > 'lllllllllllllllllllllllllllllllllllllllllllll'...
> > that's allright,
> > but if I write:
> > word=string('long strings are my problem')

> > together=string(word,word,word,word,word,word,word)
> > print,strlen(together)
> >          162          27
> > help,togehter     ==>       TOGETHER        STRING    = Array[2]
> >
> > What's happen and how can I stop it ?
> 
> If you want to string words together, you should
> use the + sign:
> 
>   IDL> word1 = 'Hello '
>   IDL> word2 = 'Karsten'
>   IDL> word3 = ': How are you?"
>   IDL> sentence = word1 + word2 + word3
>   IDL> Print, sentence
> 
>      Hello Karsten: How are you?
> 
> Cheers,
> 
> David
> 
> --
> David Fanning, Ph.D.
> Fanning Software Consulting
> Phone: 970-221-0438 E-Mail: davidf@dfanning.com
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155