What you might want are the following commands:
inString( to locate a substring in a larger string. In this case, your substring is just a space.
sub( has two uses, but you will want to use it to extract a part of the string.
So what you want is the first part of the string before a space, the second part of the string after the space (up to another space or end of the string) and if there is anything remaining, return that. Instead of using "any number of spaces," if you restricted it to specifically 1 space, that would make things easier. However, here is the code I came up with:
Lets get the length of the string and locate the first space:
inString(Str1," ;B is now the location of the first space in the string.
If not(Ans ;means there was no space token in the string
Now at this point, the first part of the string is returned. In the next part, we skip everything if there is nothing left in the string (for example, if Str1 was "HELLO"). Otherwise, we search the string until the first non-space. For that, I will use a While loop. Just in case the string rest of the string is spaces, I will throw in an extra condition to prevent a domain error:
While Ans<N and sub(Str1,Ans,1)="
I could have done B+1→B in the main loop instead of putting B outside the loop and using Ans. That way will be smaller, but I believe this way is faster. If speed isn't an issue, do this:
While B<N and sub(Str1,B,1)="
Now at this point, either B>N which implies that there are no more substrings to extract, B points to the next non-space. So now we look for the next space after B, using the optional third argument of inString(
sub(Str1,B,A-B ;this is the second substring
Note that there isn't an End statement yet— we aren't finished. Now we extract whatever is left of the string, if anything:
sub(Str1,A,N-A+1 ;your final substring
Putting it all together and making a few adjustments, you will get your results in Str2, Str3, and Str4. If there are no substrings for those, they will have a single space instead:
While B+1<N and Str4=sub(Str1,B,1
So now "bob" returns:
"bob " returns the same thing
"bob joe" returns
"bob joe cake" returns
I hope this is what you were looking for and that it helps!
Input in Str1, Output in Str2, Str3, Str4