Julia Language String Normalization Case-Insensitive String Comparison

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Strings can be compared with the == operator in Julia, but this is sensitive to differences in case. For instance, "Hello" and "hello" are considered different strings.

julia> "Hello" == "Hello"
true

julia> "Hello" == "hello"
false

To compare strings in a case-insensitive manner, normalize the strings by case-folding them first. For example,

equals_ignore_case(s, t) =
    normalize_string(s, casefold=true) == normalize_string(t, casefold=true)

This approach also handles non-ASCII Unicode correctly:

julia> equals_ignore_case("Hello", "hello")
true

julia> equals_ignore_case("Weierstraß", "WEIERSTRASS")
true

Note that in German, the uppercase form of the ß character is SS.



Got any Julia Language Question?