Capitalize 1st word of an character array

 Accepted Answer

regexprep(S, '[a-z]', '(??@upper($1))', 'once' )

3 Comments

S = '99this';
regexprep(S, '[a-z]', '(??@upper($1))', 'once' ) % incorrect replacement
ans = '99(??@upper($1))his'
regexprep(S, '[a-z]', '${upper($0)}', 'once' )
ans = '99This'
There was a slight problem... incase the input was 'Nayeb' it shows the output 'NAyeb'... to solve the problem this is a slightly edited version. Thanks @Adam Danz & @Walter Roberson
S='NAyeb'
S = 'NAyeb'
regexprep(lower(S), '[a-z]', '${upper($0)}', 'once' )
ans = 'Nayeb'

Sign in to comment.

More Answers (1)

s = "99this"
s = "99this"
firstletter = letterBoundary("start")+lettersPattern(1)
firstletter = pattern
Matching: letterBoundary("start") + lettersPattern(1)
replace(s, firstletter, upper(extract(s, firstletter)))
ans = "99This"

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!