Prev: Call by reference / references
Next: matlab function
From: us on 6 Mar 2010 10:39 "Jan Simon" > It fails if the last character of S is a space. > Kind regards, Jan ....or any other whitespace; in particular: a TAB,... us
From: Jan Simon on 6 Mar 2010 11:16 Dear Urs! > > It fails if the last character of S is a space. > > Kind regards, Jan > ...or any other whitespace; in particular: a TAB,... > us I don't understand. This does not fail, if the last character is a TAB: ind = [1, findstr(S, ' ') + 1]; Do you mean: ind = [1, find(isspace(S)) + 1] ?! confused, Jan
From: us on 6 Mar 2010 13:09 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hmtv45$73g$1(a)fred.mathworks.com>... > Dear Urs! > > > > It fails if the last character of S is a space. > > > Kind regards, Jan > > > ...or any other whitespace; in particular: a TAB,... > > us > > I don't understand. This does not fail, if the last character is a TAB: yes, but if there's any TAB between other chars... s=lower(sprintf('BLUE\tRED\tGREEN\t')); ix=[1,strfind(s,' ')+1]; s(ix)=upper(s(ix)) % s = Blue red green us
From: Doug Schwarz on 6 Mar 2010 14:04
In article <hmu5o3$pkj$1(a)fred.mathworks.com>, "us " <us(a)neurol.unizh.ch> wrote: > "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message > <hmtv45$73g$1(a)fred.mathworks.com>... > > Dear Urs! > > > > > > It fails if the last character of S is a space. > > > > Kind regards, Jan > > > > > ...or any other whitespace; in particular: a TAB,... > > > us > > > > I don't understand. This does not fail, if the last character is a TAB: > > yes, but if there's any TAB between other chars... > > s=lower(sprintf('BLUE\tRED\tGREEN\t')); > ix=[1,strfind(s,' ')+1]; > s(ix)=upper(s(ix)) > % s = Blue red green > > us How about a modification of Urs' original idea? If I have my regular expression skills in order, this should look for any contiguous block of non-whitespace and make the first character upper case and any subsequent characters lower case: str = 'rED GrEEn BluE'; regexprep(str,'(\S)(\S*)','${upper($1)}${lower($2)}') -- Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address. |