Re: Adding values to a string [message #49037] |
Thu, 08 June 2006 13:44 |
rafaloos
Messages: 15 Registered: January 2006
|
Junior Member |
|
|
It works perfectly ...
Thank you very much for the fast reply
Rick Towler wrote:
> One way:
>
> text='M5A,060530,181005,4302003340bf,1149012,,,,,15.70765,89 3.439514,7.73610973'
>
> IDL> parts=STRSPLIT(text, ',', /EXTRACT, /PRESERVE_NULL)
> IDL> parts[WHERE(parts eq '')] = '0'
> IDL> newText = STRJOIN(parts, ',', /SINGLE)
> IDL> print, newText
> M5A,060530,181005,4302003340bf,1149012,0,0,0,0,15.70765,893. 439514,7.73610973
>
> -Rick
>
> rafaloos@gmail.com wrote:
>> Hi ...
>> I have a string like this:
>>
>> 'M5A,060530,181005,4302003340bf,1149012,,,,,15.70765,893.439 514,7.73610973'
>>
>> As you can see this string has some extra commas. Values were supposed
>> to be in between these commas, but they are not.
>>
>> I want to ADD some zeros in the above string so that in the end my
>> string will be like this:
>>
>> 'M5A,060530,181005,4302003340bf,1149012,0,0,0,0,15.70765,893 .4395141,7.73610973'
>>
>> Is there a easy way to do that ?
>>
>> Thank you
>>
|
|
|
Re: Adding values to a string [message #49038 is a reply to message #49037] |
Thu, 08 June 2006 13:34  |
Rick Towler
Messages: 821 Registered: August 1998
|
Senior Member |
|
|
One way:
text='M5A,060530,181005,4302003340bf,1149012,,,,,15.70765,89 3.439514,7.73610973'
IDL> parts=STRSPLIT(text, ',', /EXTRACT, /PRESERVE_NULL)
IDL> parts[WHERE(parts eq '')] = '0'
IDL> newText = STRJOIN(parts, ',', /SINGLE)
IDL> print, newText
M5A,060530,181005,4302003340bf,1149012,0,0,0,0,15.70765,893. 439514,7.73610973
-Rick
rafaloos@gmail.com wrote:
> Hi ...
> I have a string like this:
>
> 'M5A,060530,181005,4302003340bf,1149012,,,,,15.70765,893.439 514,7.73610973'
>
> As you can see this string has some extra commas. Values were supposed
> to be in between these commas, but they are not.
>
> I want to ADD some zeros in the above string so that in the end my
> string will be like this:
>
> 'M5A,060530,181005,4302003340bf,1149012,0,0,0,0,15.70765,893 .4395141,7.73610973'
>
> Is there a easy way to do that ?
>
> Thank you
>
|
|
|