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