V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
mytry
V2EX  ›  程序员

字符串长度必须在 toUpperCase() 之后判断,否则可能会溢出~

  •  
  •   mytry · Feb 15, 2019 · 1941 views
    This topic created in 2629 days ago, the information mentioned may be changed or developed.
    'αß'.toUpperCase() === 'ΑSS'
    

    ...

    'ffi'.toUpperCase() === 'FFI'
    

    ...

    2 replies    2019-02-15 13:56:47 +08:00
    yuikns
        1
    yuikns  
       Feb 15, 2019
    'ffi' == '\ufb03'
    true
    'ß' == '\u00DF'
    true

    https://stackoverflow.com/questions/9127644


    > "ß" character is equivalent to "ss" (used in German, for example), and this is defined so in your Locale (the Locale you are using in your app).

    https://www.reddit.com/r/javascript/comments/9i455b

    > When using capital letters, SS has historically stood for ß. However, in some fonts, there also exists a corresponding capital letter; its usage is optional <§ 25 E3>.

    这个讨论还是挺多的。

    不太明白 "否则可能会溢出" 这个结论。用啥字符串就拿啥 .length 呗。要是 for each,不妨试试 map foreach 等?
    mytry
        2
    mytry  
    OP
       Feb 15, 2019
    说错了不是溢出,应该是会被截断。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3483 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:05 · PVG 20:05 · LAX 05:05 · JFK 08:05
    ♥ Do have faith in what you're doing.