I have a text wave each point of the wave is a string that is of different lengths. The last three character of the string is of use to me and I want to extract the last three characters. I also want to use a if-statement on the second to last character--if this character is a dash line or not, so I would also like to parse out this character as well. What I can think of is counting the number of characters in the string using strlen and do maths. Is there a better way to do these kind of tasks?
That sounds like a good approach. Can you get it to work?
Depending on the format of the string you can look at SplitString to parse out different elements of the string. If the strings are all of a certain format this works well. Other people on the forum will have alternative solutions to this problem.
StrLen sounds like a good way of doing it. You could also look at Extract and Grep. Grep is really powerful for selecting strings matching certain criteria, but the regular expressions needed are not easy to understand. Just as an example, this is a Grep command I use to find the positions of lines with the format [..something..] in a loaded text file Grep/INDX/E="(^\\[)(.+)(\\]$)" LoadedTextWave as TempGrepWave
Thank you very much guys! I was able to get the strlen to work like jjweimer has shown. Splitstring, extract and grep look really powerful too. It does take some efforts to understand grep though. I am still figuring it out. Thank you all!
... Splitstring, extract and grep look really powerful too. It does take some efforts to understand grep though. I am still figuring it out. Thank you all!
Grep (and its invocations with splitstring or extract) is useful to pull out portions of strings that follow patterns. Think of searching for tags in HTML < ... > or brackets [ ... ] or other demarkations that denote boundaries of words or contents. To pull out portions of strings according to position in the string, the better approach is to use index notations as demonstrated.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Depending on the format of the string you can look at
SplitString
to parse out different elements of the string. If the strings are all of a certain format this works well. Other people on the forum will have alternative solutions to this problem.March 31, 2017 at 10:27 pm - Permalink
StrLen
sounds like a good way of doing it. You could also look atExtract
andGrep
. Grep is really powerful for selecting strings matching certain criteria, but the regular expressions needed are not easy to understand. Just as an example, this is a Grep command I use to find the positions of lines with the format [..something..] in a loaded text fileGrep/INDX/E="(^\\[)(.+)(\\]$)" LoadedTextWave as TempGrepWave
April 1, 2017 at 02:00 am - Permalink
string chars = tstring[twlen-4,]
string tchar = chars[0]
strswitch tchar
...
end switch
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
April 1, 2017 at 11:48 am - Permalink
April 3, 2017 at 09:48 pm - Permalink
Grep (and its invocations with splitstring or extract) is useful to pull out portions of strings that follow patterns. Think of searching for tags in HTML < ... > or brackets [ ... ] or other demarkations that denote boundaries of words or contents. To pull out portions of strings according to position in the string, the better approach is to use index notations as demonstrated.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
April 4, 2017 at 05:29 am - Permalink
April 5, 2017 at 05:45 pm - Permalink