Capitalize 1st word of an character array

2 visualizaciones (últimos 30 días)
Nayeb Hasin
Nayeb Hasin el 16 de Jun. de 2022
Comentada: Nayeb Hasin el 16 de Jun. de 2022
Using regexprep how do I convert this '99this' to this '99This'?

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (1)

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

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by