Hi. Suppose I have a string "cat,dog,,,,mouse,". Is there a simple way to break this string into a list of substrings in such a way that the result is {"cat", "dog", "", "", "", "mouse", ""}? I've been using the Words() function, but it seems to treat consecutive delimiters in series as just one:
//Desired list result should be {"cat", "dog", "", "", "", "","mouse", ""}<BR /><BR />Names Default to Here(1);
str = "cat,dog,,,,mouse,";
lis = Words(str, ","); //This returns {"cat", "dog", "mouse"}I tried to format the string ahead of time using Substitute:
newstr = Substitute(str, ",,", ", ,"); //Returns "cat,dog, ,, ,mouse," <BR />lis = Words(newstr, ","); //Returns {"cat", "dog", " ", " ", "mouse"}.<BR />finalis = Substitute(lis, " ", ""); //Returns {"cat", "dog", "", "", "mouse"} Note that there are still 2 consecutive delimiters between dog and mouse after the first Substitute() command. Thus, following the Words() function, one of the empty items between dog and mouse is still missing. Also note that the empty item at the end of the string is missing from the list.
Does anyone know of a way to do this, preferably one that does not involve a for loop?
Another way in case you don't have access to Items() function in your version of JMP.
Note that you will have to choose a delimiter that will not be present in your list items and is not your original delimiter. In this example I am using #.
lis = Parse( Substitute( Char( Substitute( Words( Substitute( str, ",", "#,#" ), "," ), "#", "" ) ), "#", "" ) );
[edit] fixed for leading and trailing null list items.
Check the Items() function. It's just like Words(), but consecutive delimiters are treated as though they have a word between them.