Converting a string to lower case

Elm:
Converting a string to lower case

How to:

Elm uses the String.toLower function to convert text:

import String

lowercaseString : String -> String
lowercaseString text =
    String.toLower text

-- Usage
result : String
result =
    lowercaseString "HeLLo, WoRLD!"

-- Output: "hello, world!"

Deep Dive

Elm’s String.toLower comes from Elm’s core String library, with internationalization taken into account. Historically, case conversion has evolved from basic ASCII to full Unicode support due to the need for international text handling.

In some languages like Javascript, there are alternatives like toLowerCase() and toLocaleLowerCase(), where the latter considers locale-specific rules. In Elm, String.toLower should suffice for most cases unless dealing with locale-sensitive operations, which might require a custom implementation.

A detail to remember is that case conversion isn’t always a one-to-one; some characters may not have a lowercase equivalent, and others may change size (e.g., converting “ß” in German).

See Also