I have a string "value" and need to convert it to "Value" how can we do that using camel case Output : value = Value
Asked
Active
Viewed 105 times
2
-
Use Elixir? https://hexdocs.pm/elixir/Macro.html#camelize/1 :) – Roger Lipscombe Sep 02 '22 at 10:50
1 Answers
3
You can use string:titlecase/1
:
> string:titlecase("value").
"Value"
Edit: this would technically not be a full camel case implementation (which would need to split on some character and title case each chunk), but it satisfies your example.
For converting snake_case
to CamelCase
, for instance, you could do:
> String = "hello_world",
Chunks = string:split(String, "_"),
Chunks2 = lists:map(fun string:titlecase/1, Chunks),
string:join(Chunks2, "").
"HelloWorld"

sabiwara
- 2,775
- 6
- 11