可以使用名为 string:titlecase/1
的函数,如下所示:
Eshell V11.0 (abort with ^G)
1> string:titlecase("hello").
"Hello"
2>
或者...如果您不想将整个字符串首字母大写,而只想将第一个单词首字母大写...
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>
但是如果你不想使用花哨的字符串函数,你可以使用模式匹配...
4> f(Rest).
ok
5> [FirstChar|Rest] = "hello".
"hello"
6> [string:to_upper(FirstChar)|Rest].
"Hello"
7>