Reputation: 5789
I would like to remove the first letter and replace the second one by its lowercase
Example :
a = 'iSvalid'
to a = 'svalid'
I've tried strrep( a,'i','')
which gives 'Svalid'
but I would like also to convert the first capital letter to lower case.
Upvotes: 0
Views: 241
Reputation: 20319
Here is my version os @petrichor's answer. I've separated each function to make the code more readable.
a = 'isValid';
b = a(2:end);
b(1) = lower(b(1));
Upvotes: 0
Reputation: 74940
For a general solution, which will e.g. work on cell arrays of strings, or on multiple words in the same string, there is regexprep
:
a = 'iSvalid';
%# discard first letter of word, replace second by lower-case version
b = regexprep(a,'\<\w(\w)','${lower($1)}')
b =
svalid
Upvotes: 0
Reputation: 6569
>> a = 'iSvalid';
>> b = strcat(lower(a(2)), a(3:end))
b =
svalid
You can also use brackets:
>> b = [lower(a(2)) a(3:end)]
b =
svalid
Upvotes: 3