[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: string to array conversion
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('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 ?
>
> 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 [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[