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

2019-02-15 13:26:33 +08:00
 mytry
'αß'.toUpperCase() === 'ΑSS'

...

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

...

1614 次点击
所在节点    程序员
2 条回复
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
2019-02-15 13:56:47 +08:00
说错了不是溢出,应该是会被截断。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/535289

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX