string to array conversion [message #21005] |
Wed, 02 August 2000 00:00  |
Karsten Schmidt
Messages: 4 Registered: July 2000
|
Junior Member |
|
|
Hi all,
I want to create very long strings (300 characters and more), but
sometimes IDL makes an array with three or four dimensions. How can I
stop this conversion ?
Thanks for answer
Karsten
|
|
|
|
Re: string to array conversion [message #21136 is a reply to message #21005] |
Fri, 11 August 2000 00:00  |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
Karsten Schmidt wrote:
>
> Hi Alex, thanks for your answer,
> I want to change the stringlength or produce new strings (delete and add
> some words), example:
>
> a=string('llllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllll')
>
> 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
>
> What's happen and how can I stop it ?
>
> Karsten
Hallo Karsten,
another possible solution is the format option for the string
function, see example below.
Cheers,
Martin
; generate two example strings of 300 byte length each
b=bytarr(300)+65B
c=bytarr(300)+69B
bs=string(b)
help,bs
; BS STRING =
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'...
print,strlen(bs)
; 300
cs=string(c)
; if you use only the string function, IDL will generate a string array
ds=string(bs,cs)
help,ds & print,strlen(ds)
; DS STRING = Array[2]
; 300 300
; however, if you add the format option, you can concetanate the strings
ds=string(bs,cs,format='(A,A)')
help,ds & print,strlen(ds)
; DS STRING =
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'...
;
600
--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
|
|
|
Re: string to array conversion [message #21138 is a reply to message #21005] |
Fri, 11 August 2000 00:00  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
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.h tml
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('llllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllll')
>>
>> 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
|
|
|
Re: string to array conversion [message #21162 is a reply to message #21005] |
Thu, 10 August 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
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:
>
> a=string('llllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllll')
>
> 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
|
|
|
Re: string to array conversion [message #21164 is a reply to message #21005] |
Thu, 10 August 2000 00:00  |
Karsten Schmidt
Messages: 4 Registered: July 2000
|
Junior Member |
|
|
Hi Alex, thanks for your answer,
I want to change the stringlength or produce new strings (delete and add
some words), example:
a=string('llllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllllllllllllllllllllll llllllllllllllllllllllllllllllllllllllllll')
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 ?
Karsten
Alex Schuster schrieb:
> Karsten Schmidt wrote:
>
>> I want to create very long strings (300 characters and more), but
>> sometimes IDL makes an array with three or four dimensions. How can I
>> stop this conversion ?
>
> Can you give us an example of what exactly you are doing? I did not
> encounter this behaviour before, strings have always worked fine for me.
>
> IDL> help, string( bytarr( 20000 ) + 65b )
> <Expression> STRING =
> 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'...
>
> Alex
> --
> Alex Schuster Wonko@weird.cologne.de PGP Key available
> alex@pet.mpin-koeln.mpg.de
|
|
|