These two functions parse a string (character array) or cell array of strings based on one or more delimiters. I designed it as a replacement for strtok.m because it did not meet my expectations or requirements as a string parsing function. These functions no doubt require further enhancement and refinement so any suggestions you might have would be welcome.
Does exactly what I needed. Select a portion of a string between 2 delimiters.I couldn't for the life of it get strtok to work this way.
Exactly what I needed!! Thanks soooo much :)
Those are good comments but your code will not output an empty token if the input string ends with a delimiter. My code takes care of this occurrence. I will update my code to use your speedy alternative. Thanks for your input.
and on second thought, why not use regexprep en strread so that you can retrieve the non-existent strings anyway:
s = 'what a great , day'
tokens = ', ' ;
tokens2 = ['[' tokens ']'] ;
r = strread(regexprep(s,tokens2,char(1)),'%s','delimiter',char(1))
Just wondering. What about using STRREAD?
which will not return empty cells (i.e., no-existent strings between two consecutive tokens.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.