IDL_STRING.split vs strsplit [message #94765] |
Mon, 02 October 2017 03:11  |
trisb
Messages: 18 Registered: November 2010
|
Junior Member |
|
|
Hi everyone,
I have the following string
mystring = "MY.NESTED.FILENAME.ARGH"
What I want to do is split the string into substrings with the dot as the dividing character. Two methods area available but only one delivers:
This works:
IDL> out = strsplit(mystring,'.',/extract)
IDL> help,out
OUT STRING = Array[4]
IDL> print,out
MY NESTED FILENAME ARGH
This doesn't:
IDL> out = mystring.split('.')
IDL> help,out
OUT STRING = Array[24]
IDL> print,out
Any clue as to why the second one behaves that way? Note that this only happens with the dot, so I must be missing something fundamental.
Thanks,
F.
|
|
|
Re: IDL_STRING.split vs strsplit [message #94766 is a reply to message #94765] |
Mon, 02 October 2017 05:14   |
Burch
Messages: 28 Registered: December 2013
|
Junior Member |
|
|
On Monday, October 2, 2017 at 5:11:45 AM UTC-5, trisb wrote:
> Hi everyone,
>
> I have the following string
>
> mystring = "MY.NESTED.FILENAME.ARGH"
>
> What I want to do is split the string into substrings with the dot as the dividing character. Two methods area available but only one delivers:
>
> This works:
>
> IDL> out = strsplit(mystring,'.',/extract)
> IDL> help,out
> OUT STRING = Array[4]
> IDL> print,out
> MY NESTED FILENAME ARGH
>
>
> This doesn't:
>
> IDL> out = mystring.split('.')
> IDL> help,out
> OUT STRING = Array[24]
> IDL> print,out
>
>
>
> Any clue as to why the second one behaves that way? Note that this only happens with the dot, so I must be missing something fundamental.
>
> Thanks,
> F.
Unlike STRSPLIT() the SPLIT method requires the argument to be in the format of a regular expression. Try this instead:
IDL> out = mystring.split('\.')
IDL> help, out
OUT STRING = Array[4]
IDL> print, out
MY NESTED FILENAME ARGH
More on regular expressions: https://www.harrisgeospatial.com/docs/learning_about_regular _e.html
-Jeff
|
|
|
|