strsplit vectorized [message #85835] |
Thu, 12 September 2013 12:33  |
spluque
Messages: 33 Registered: September 2013
|
Member |
|
|
Hi,
I realize that strsplit() only takes a scalar for its first argument string. I would like to have that operation done on all the elements of a string vector. The vector contains time stamps (e.g. '2013-09-10 00:00:00'), that I am trying to replace by the concatenation of each component (e.g. '20130910000000' in the preceding example). How can this be done without a complicated loop?
Thanks,
Seb
|
|
|
|
Re: strsplit vectorized [message #85837 is a reply to message #85836] |
Thu, 12 September 2013 12:50   |
John Correira
Messages: 25 Registered: August 2011
|
Junior Member |
|
|
On 09/12/2013 03:43 PM, spluque@gmail.com wrote:
> An update after finding out that IDL >= 8.0 does allow arrays as input...
>
>
> On Thursday, September 12, 2013 2:33:54 PM UTC-5, spl...@gmail.com
> wrote:
>> Hi,
>>
>>
>>
>> I realize that strsplit() only takes a scalar for its first
>> argument
string. I would like to have that operation done on all the elements of
a string vector. The vector contains time stamps (e.g. '2013-09-10
00:00:00'), that I am trying to replace by the concatenation of each
component (e.g. '20130910000000' in the preceding example). How can this
be done without a complicated loop?
>>
>>
>>
>> Thanks,
>>
>> Seb
For a IDL 7 compatible answer, if the data always in that format (i.e.
YYYY-MM-DD HH:MM:SS) you could do something like
new = STRJOIN(strmid(array,[0,5,8,11,14,17],[4,2,2,2,2,2]))
John
|
|
|
Re: strsplit vectorized [message #85839 is a reply to message #85837] |
Fri, 13 September 2013 06:34   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Thursday, September 12, 2013 3:50:54 PM UTC-4, John Correira wrote:
>
> For a IDL 7 compatible answer, if the data always in that format (i.e.
>
> YYYY-MM-DD HH:MM:SS) you could do something like
>
>
>
> new = STRJOIN(strmid(array,[0,5,8,11,14,17],[4,2,2,2,2,2]))
Nice. I had previously complained about the clumsy syntax of STRMID when you just want to a single substring from each element of a string array. (You can't use a scalar to specify the first position or string length -- http://www.idlcoyote.com/code_tips/strmidvec.html ) But when you want to extract multiple substrings from each element of a string array then the syntax becomes elegant.
|
|
|
Re: strsplit vectorized [message #85840 is a reply to message #85837] |
Fri, 13 September 2013 11:41  |
spluque
Messages: 33 Registered: September 2013
|
Member |
|
|
On Thursday, September 12, 2013 2:50:54 PM UTC-5, John Correira wrote:
> On 09/12/2013 03:43 PM, spluque@gmail.com wrote:
>
>> An update after finding out that IDL >= 8.0 does allow arrays as input...
>
>>
>
>
>
>>
>
>> On Thursday, September 12, 2013 2:33:54 PM UTC-5, spl...@gmail.com
>
>> wrote:
>
>>> Hi,
>
>>>
>
>>>
>
>>>
>
>>> I realize that strsplit() only takes a scalar for its first
>
>>> argument
>
> string. I would like to have that operation done on all the elements of
>
> a string vector. The vector contains time stamps (e.g. '2013-09-10
>
> 00:00:00'), that I am trying to replace by the concatenation of each
>
> component (e.g. '20130910000000' in the preceding example). How can this
>
> be done without a complicated loop?
>
>>>
>
>>>
>
>>>
>
>>> Thanks,
>
>>>
>
>>> Seb
>
>
>
>
>
> For a IDL 7 compatible answer, if the data always in that format (i.e.
>
> YYYY-MM-DD HH:MM:SS) you could do something like
>
>
>
> new = STRJOIN(strmid(array,[0,5,8,11,14,17],[4,2,2,2,2,2]))
>
>
>
> John
Thank you, strmid takes multiple ranges!
Seb
|
|
|