Skip to content

Case conversion — toUpperCase can change the length

Level: 201 · for anyone who compares strings without regard to case

Stub — an outline, not a lesson. There is no runnable example behind this page yet, so nothing on it has been through the check that backs every other claim in this library. The questions below are what the finished page has to answer.

One line: Case mapping follows Unicode's full rules, so it can change length: "straße".toUpperCase() is "STRASSE" and "İ".toLowerCase() is two code units; lowercasing both sides therefore misses that "straße" and "STRASSE" match, which localeCompare with sensitivity: "base" finds.

Keywords: toUpperCase, toLowerCase, toLocaleUpperCase, toLocaleLowerCase

What the finished page will answer

  • Which characters change a string's length under toUpperCase or toLowerCase: ß, fi, ʼn, İ?
  • What do toLocaleUpperCase and toLocaleLowerCase do to i, I and İ in en, tr and lt?
  • Why does "ΣΑΣ".toLowerCase() end in ς rather than σ?
  • Why is a.toLowerCase() === b.toLowerCase() not a case-insensitive comparison, and what do localeCompare with sensitivity: "base" and "accent" do instead?
  • Does "ß".toUpperCase().toLowerCase() give back ß?

Examples it will need

  • case_conversion_length_js.js — strings whose length changes under toUpperCase or toLowerCase (ß, fi, ʼn, İ), with the lengths and code points before and after
  • case_conversion_locale_js.js — toLocaleUpperCase and toLocaleLowerCase of i, I, İ and Ì in en, tr and lt, then the Greek final sigma
  • case_conversion_compare_js.js — case-insensitive comparison three ways (lowercasing both sides, localeCompare with sensitivity: "base", and with "accent") on straße/STRASSE and résumé/RESUME

See also

Sources to start from