Capitalize 1st word of an character array

5 次查看(过去 30 天)
Using regexprep how do I convert this '99this' to this '99This'?

采纳的回答

Walter Roberson
Walter Roberson 2022-6-16
regexprep(S, '[a-z]', '(??@upper($1))', 'once' )
  3 个评论
Nayeb Hasin
Nayeb Hasin 2022-6-16
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'

请先登录,再进行评论。

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2022-6-16
编辑:Sean de Wolski 2022-6-16
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"

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by