File Exchange

image thumbnail

Parse Strings Using Delimiters

version 1.0 (4.14 KB) by

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

2 Downloads

Updated

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.

Comments and Ratings (8)

Santosh

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.

Exactly what I needed!! Thanks soooo much :)

mh3456 Helm

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.

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

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
MATLAB 7.3 (R2006b)

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

» Watch video