Capitalizing every word in a string
Show older comments
str='The bottom of the deep blue sea'
strN='The Bottom Of The Deep Blue Sea'
To convert the string 'str' to 'strN' is used:
regexprep(str,'(\<[a-z])','${upper($1)}')
Can someone please xeplain this? Another suggestion which did not work was:
regexprep(str,'(\<\w)','${upper($1)}')
Is there a simpler (it is ok if it is longer) way of doing this?
1 Comment
Stephen23
on 17 Jan 2019
regexprep(str,'(\w)(\w+)','${upper($1)}$2')
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings 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!