View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Parse Strings Using Delimiters

4.6 | 5 ratings Rate this file 3 Downloads (last 30 days) File Size: 4.14 KB File ID: #17999 Version: 1.0

Parse Strings Using Delimiters


Jeff Jackson (view profile)


13 Dec 2007 (Updated )

These two functions parse a string or cell array of strings based on one or more delimiters.

| Watch this File

File Information

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.

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
24 Sep 2014 Santosh

15 Apr 2013 Reza Farrahi Moghaddam

19 Sep 2012 varunr

varunr (view profile)

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.

06 Apr 2011 Nando Hoffman

Exactly what I needed!! Thanks soooo much :)

08 Apr 2009 mh3456 Helm

19 Dec 2007 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.

Comment only
18 Dec 2007 Jos

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

Comment only
18 Dec 2007 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.

Comment only

Contact us