在数字上使用 String.prototype.toUpperCase() 或 String.prototype.toLowerCase() 安全吗?

Is it safe to use String.prototype.toUpperCase() or String.prototype.toLowerCase() on numbers?

我有一些可能也包含数字字符的动态字符串。例如。 1sFw23fD。我想将此字符串中的所有字母转换为大写字母。那就是我想把1sFw23fD转换成1SFW23FD。为此,我使用 toUpperCase() 方法。我不确定 toUpperCase() 应该如何处理数字和字母数字字符。使用 "1sFw23fD".toUpperCase() 安全吗?

如回答中所述,数字不受这些方法的影响。请提供一些参考,如 w3c 规范或 mdn 等。干杯。

就我而言,你现在做的事情没有错。

> "123123123123a".toUpperCase()
'123123123123A'

是的,很安全。它只会影响适当情况下的字符,而不会影响其余的字符。

编辑:"The toUpperCase method has no effect on non-alphabetic characters." 来源:https://docs.microsoft.com/en-us/scripting/javascript/reference/touppercase-method-string-javascript

是的,你可以使用它。在这种情况下“1sFw23fD”已经是一个字符串>注意它周围的引号。

您也可以使用css 属性 text-align:uppercase

.uppercase {
  text-transform: uppercase;
}
<div class='uppercase'>
  1sFw23fD
</div>

是的。如 http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-string-prototype-object 中所定义,它只是替换在 Unicode table 中具有代表 uppercase/lowercase 值的字符。那应该不会错...:[=​​11=]

"For each code point c in cpList, if the Unicode Character Database provides a language insensitive lower case equivalent of c then replace c in cpList with that equivalent code point(s)."