Converting a string to lower case

Converting a string to lower case

How to:

Elixir makes it a breeze. Use the String.downcase/1 function:

original = "LoReM IPSUM"
lowercased = String.downcase(original)

IO.puts original
IO.puts lowercased


lorem ipsum

Deep Dive

Elixir’s string handling is Unicode aware, which matters a lot for proper lower-casing across different alphabets and scripts. Historically, string manipulation in programming languages didn’t always account for this complexity.

Before Elixir’s current approach, some older languages offered simplistic methods that might work fine for English but would trip on languages like Turkish, where, for instance, an uppercase ‘i’ does not become ‘I’ but rather ‘İ’.

Internally, Elixir uses Unicode’s case mapping to get this right. And there are alternatives; for example, String.downcase/2 allows you to specify a locale, which comes in handy for language-specific behaviors.

turkish = "GÖLCÜK"
String.downcase(turkish, :tr)



In the example above, notice how the ‘I’ character is preserved appropriately according to Turkish casing rules.

See Also