Help with SplitString to extract sample name out of file name
antonin.grenier
I have a series of waves with the following names:
FeCl2_x0.000_y0.000_10.00s_96470_saxs.dat
FeCl2_x0.000_y0.000_10.00s_96471_saxs.dat
FeCl2_x0.000_y0.000_10.00s_96472_saxs.dat
etc.
I want to extract the "FeCl2" out of the corresponding string (I used WaveList and StringFromList), i.e., anything after the first underscore I do not care about.
How does that translate to the regExprStr in the SplitString function? Or perhaps anoter approach would be more efficient?
Thanks for your help
AG
Hi,
One way is to use stringfromlist again. let's assume the string is filename such as FeCl2_x0.000_y0.000_10.00s_96470_saxs.dat
Then:
String text_you_want
text_you_Want= stringfromlist(0,filename,"_")// 0 is index, i.e. first, filename is the original string, and "_" says use underscore as the delimiter in the list.
Andy
December 9, 2020 at 01:00 pm - Permalink
Assuming that you do not know the FeCl2 in advance
^([a-z,A-Z,0-9])+
This will return the first "word" up to the underscore.
December 9, 2020 at 01:02 pm - Permalink
In reply to Hi, One way is to use… by hegedus
That worked.
Thanks Andy
December 9, 2020 at 01:16 pm - Permalink
Yeah!
I got one right! With this lockdown, I take whatever I can get.
Andy
December 9, 2020 at 01:31 pm - Permalink