How to convert the first letter of a string to uppercase in Erlang

A function named can be used as follows: string:titlecase/1

Eshell V11.0  (abort with ^G)
1> string:titlecase("hello").
"Hello"
2>

Or...if you don't want to capitalize the entire string, but only the first word...

2> [First|Rest] = string:lexemes("this name is Nice", [$\s]).
["this","name","is","Nice"]
3> string:join([string:titlecase(First)|Rest], " ").
"This name is Nice"
4>

But if you don't want to use fancy string functions, you can use pattern matching...

4> f(Rest).
ok
5> [FirstChar|Rest] = "hello".
"hello"
6> [string:to_upper(FirstChar)|Rest].
"Hello"
7>

Guess you like

Origin blog.csdn.net/qq_25231683/article/details/131259643