I have a string "data".How can I convert only the first character to uppercase and get a new string in the form of "Data"?
I have a string "data".How can I convert only the first character to uppercase and get a new string in the form of "Data"?
You can use the amazing function called string:titlecase/1, like this:
1> string:titlecase("data").
"Data"
Or… if you don't want to title-case your whole string, but just the first word…
5> [First|Rest] = string:lexemes("this data is Nice", [$\s]).
["this","data","is","Nice"]
6> string:join([string:titlecase(First)|Rest], " ").
"This data is Nice"
But if you want no fancy string function, you can just use pattern-matching…
11> [FirstChar|Rest] = "data".
"data"
12> [string:to_upper(FirstChar)|Rest].
"Data"
13>