Capitalize 1st word of an character array

2 Ansichten (letzte 30 Tage)
Nayeb Hasin
Nayeb Hasin am 16 Jun. 2022
Kommentiert: Nayeb Hasin am 16 Jun. 2022
Using regexprep how do I convert this '99this' to this '99This'?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Jun. 2022
regexprep(S, '[a-z]', '(??@upper($1))', 'once' )
  3 Kommentare
Walter Roberson
Walter Roberson am 16 Jun. 2022
Thanks, Adam.
Nayeb Hasin
Nayeb Hasin am 16 Jun. 2022
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'

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sean de Wolski
Sean de Wolski am 16 Jun. 2022
Bearbeitet: Sean de Wolski am 16 Jun. 2022
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"

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by