Code covered by the BSD License  

Highlights from
Parse Strings Using Delimiters

4.5

4.5 | 4 ratings Rate this file 11 Downloads (last 30 days) File Size: 4.14 KB File ID: #17999

Parse Strings Using Delimiters

by

 

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
Description

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 (7)
15 Apr 2013 Reza Farrahi Moghaddam  
19 Sep 2012 varunr

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

Jos,

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.

18 Dec 2007 Jos DELjos@DELjasen.nl

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

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.

Contact us