Operations with String lists and Waves

Just a few questions that have been coming up a lot lately.:

1) Is there an easy way to take the points of a wave and turn them into a string that is a list. And likewise take a string list and turn it into a text wave (or a normal wave using str2num). I usually need to use a do while loop and cycle through the number of points in the wave. Seems like there would be an easier way, to go from a string list to a wave and or the reverse.

2) Is there an easy way to remove the duplicates from a string list?

Thanks!
gh

gravityhomer wrote:

1) Is there an easy way to take the points of a wave and turn them into a string that is a list. And likewise take a string list and turn it into a text wave (or a normal wave using str2num). I usually need to use a do while loop and cycle through the number of points in the wave. Seems like there would be an easier way, to go from a string list to a wave and or the reverse.


To go from a wave to a list, I think you would need a loop. However for the reverse you can use a wave assignment statement. For example:
string text_string = "a;b;c;d;e;f;g;"
Make/T/N=(ItemsInList(text_string, ";")) text_wave
text_wave = StringFromList(p, text_string, ";")


print text_wave text_wave[0]= {"a","b","c","d","e","f","g"}
aclight wrote:
However for the reverse you can use a wave assignment statement. For example:
string text_string = "a;b;c;d;e;f;g;"
Make/T/N=(ItemsInList(text_string, ";")) text_wave
text_wave = StringFromList(p, text_string, ";")


print text_wave text_wave[0]= {"a","b","c","d","e","f","g"}


Thanks that definitely solves the string to a wave.

The reason why I wish I could easily convert a wave to a string list is that it is really easy to search string lists. Let's say I have a text wave, it is more difficult to search what point, matches a known string.
gravityhomer wrote:

The reason why I wish I could easily convert a wave to a string list is that it is really easy to search string lists. Let's say I have a text wave, it is more difficult to search what point, matches a known string.


Have you looked at the FindValue operation? With the /TXOP flag, you can search a text wave for a specific text value. Also, if you're using Igor 6 or above, you can use the Grep operation to do hard core searching of text waves. That's a bit more complicated than using FindValue, but also more powerful, for example if you need to find the same string multiple times. Finally, you could use the Extract operation, but it's less likely that you'd need to use Extract since the first two options work in most situations.
aclight wrote:
gravityhomer wrote:

The reason why I wish I could easily convert a wave to a string list is that it is really easy to search string lists. Let's say I have a text wave, it is more difficult to search what point, matches a known string.


Have you looked at the FindValue operation? With the /TXOP flag, you can search a text wave for a specific text value. Also, if you're using Igor 6 or above, you can use the Grep operation to do hard core searching of text waves. That's a bit more complicated than using FindValue, but also more powerful, for example if you need to find the same string multiple times. Finally, you could use the Extract operation, but it's less likely that you'd need to use Extract since the first two options work in most situations.


I have used grep very peripherally. Always with /INDX, as I wasn't clear on most of it. But that FindValue looks awesome, that is pretty much exactly what I am looking for.
Thanks!
gh
*** Nobody ever answered #2 ***
"2) Is there an easy way to remove the duplicates from a string list?"

Q: Is there a simple function to eliminate duplicate string elements,
as in "11-4;11-6;11-6;" -> "11-4;11-6;"

Thanks
Function/t removeStringListDuplicates(theListStr)
    String theListStr

    String retStr = ""
    variable ii
    for(ii = 0 ; ii < itemsinlist(theListStr) ; ii+=1)
        if(whichlistitem(stringfromlist(ii , theListStr), retStr) == -1)
            retStr = addlistitem(stringfromlist(ii, theListStr), retStr, ";", inf)
        endif
    endfor
    return retStr
End


Usage:
    string test = "11-4;11-6;11-6;"
    print test
    test =  removeStringlistduplicates(test)
    print test