Confusing ToUpper and ToTitle

后端 未结 5 1284
长发绾君心
长发绾君心 2021-01-01 16:18

Is there any difference between the ToUpper and the ToTitle function?

5条回答
  •  孤城傲影
    2021-01-01 16:38

    According to unicode.org

    "Because of the inclusion of certain composite characters for compatibility, such as U+01F1 latin capital letter dz, a third case, called titlecase, is used where the first character of a word must be capitalized. An example of such a character is U+01F2 latin capital letter d with small letter z. The three case forms are UPPERCASE, Titlecase, and lowercase."

    This means that when you use ToTitle or ToUpper for characters like dz, you'll probably not be able to visually distinguish the result, but the two methods will return different unicode code points.

    dz           = "\u01f3"
    ToUpper(dz)  = "\u01f1"
    ToTittle(dz) = "\u01f2"
    

    https://play.golang.org/p/OAjONd87y2

提交回复
热议问题