File Exchange

image thumbnail

Parse Strings Using Delimiters

version (4.14 KB) by Jeff Jackson
These two functions parse a string or cell array of strings based on one or more delimiters.

1 Download

Updated 23 Jan 2008

View License

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.

Cite As

Jeff Jackson (2021). Parse Strings Using Delimiters (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (8)



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.

Nando Hoffman

Exactly what I needed!! Thanks soooo much :)

mh3456 Helm

Jeff Jackson


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))

Jos x@y.z

Just wondering. What about using STRREAD?

strread(s,'%s','delimiter',' ,')

which will not return empty cells (i.e., no-existent strings between two consecutive tokens.

MATLAB Release Compatibility
Created with R2006b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!