V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
mytry
V2EX  ›  程序员

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

  •  
  •   mytry · 2019-02-15 13:26:33 +08:00 · 1610 次点击
    这是一个创建于 1890 天前的主题,其中的信息可能已经有所发展或是发生改变。
    'αß'.toUpperCase() === 'ΑSS'
    

    ...

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

    ...

    2 条回复    2019-02-15 13:56:47 +08:00
    yuikns
        1
    yuikns  
       2019-02-15 13:50:00 +08:00
    '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
       2019-02-15 13:56:47 +08:00
    说错了不是溢出,应该是会被截断。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2886 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 02:49 · PVG 10:49 · LAX 19:49 · JFK 22:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.