Capitalize 1st word of an character array

조회 수: 2 (최근 30일)
Nayeb Hasin
Nayeb Hasin 2022년 6월 16일
댓글: Nayeb Hasin 2022년 6월 16일
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
Walter Roberson
Walter Roberson 2022년 6월 16일
Thanks, Adam.
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에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by