Help with taking a small portion of a longer string
knwood
Hello,
What is the easiest way to take only the last portion of both these strings with the same code?
root:'2019_06_27':'011':
root:'2019_06_27':'011N':
I want to use either "011" or "011N" in naming a wave I am making with a function.
Thanks!
Here's one way, assuming that you would always want the last item in the colon-delimited list.
Variable numItems = itemsinlist(input,":")
string output = replacestring("'",stringfromlist(numItems-1,input,":"),"")
print output //output holds the string of interest
There may be more robust functions available for use with data folders or waves (rather than strings in general).
June 30, 2019 at 07:45 am - Permalink
SplitString, SScanF and Grep are also useful for extracting parts of a string, but StringFromList, as suggested by gsb, does seem like the perfect choice for your format.
You could also work with wave references instead of strings and then use NameOfWave(wave) to get the name of the wave or GetWavesDataFolder(waveName, kind) to get the full path or just the datafolder of the wave.
July 1, 2019 at 01:15 am - Permalink