From: quo <none@email.com>
Path: news.mathworks.com!newsfeed-00.mathworks.com!webx
Newsgroups: comp.soft-sys.matlab
Subject: Re: easy string manipolation
Message-ID: <ef0adc7.0@webx.raydaftYaTP>
Date: Thu, 16 Jun 2005 16:05:10 -0400
References: <lpc3b1p3gdrofngj4bnpurj1sj95mqp263@4ax.com>
Lines: 41
NNTP-Posting-Host: 134.131.125.49
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Xref: news.mathworks.com comp.soft-sys.matlab:285237



gigio wrote:
>
>
> Sorry for the easy question...
>
> I have some strings like these
> dummy='a, b'
> dummy='a ,b'
> dummy='a b'
> dummy='a,b'
>
> first and second terms are separated by space OR/AND comma
> I wish to separate first adn second term of the string
>
> This is my solution
> ----
> [first,second]=strtok(dummy,' ,')
> idx=find (second==',' |isspace(second) );
> second(idx)=[];
>
> first
> second
> ----
> It works, but it is not easy to generalize for string with 'n'
> terms
> Any hint ??
>
> Thank you very much!!
>

well, this is messy and regexps would probably work well here, but...

rema = strrep(dummy,',',' ');
cnt = 0;
while ~isempty(rema)
cnt = cnt+1;
[element{cnt}, rema] = strtok(rema,' ');
end

hth
-quo