JS string toLocaleUpperCase()
toLocaleUpperCase()
使用本地化(locale-specific)的大小写映射规则将输入的字符串转化成大写形式并返回结果字符串。
语法
str.toLocaleUpperCase()
str.toLocaleUpperCase(locale)
str.toLocaleUpperCase([locale, locale, ...])
参数
locale
可选
locale
参数指明要转换成大写格式的特定语言区域。如果以一个 Array
形式给出多个locales参数,最佳语言区域将被应用( 参考best available locale )。 默认的locale是主机环境的当前区域(locale)设置。
返回值
一个新的字符串,即根据本地化的大小写映射规则将输入的字符串转化成大写形式的结果。
Exceptions
- A
RangeError
(“invalid language tag: xx_yy”) is thrown if alocale
argument isn’t a valid language tag. - A
TypeError
(“invalid element in locales argument”) is thrown if an array element isn’t of type string.
描述
toLocaleUpperCase()
方法返回的是将输入的字符串根据本地化的大小写映射规则转化成的大写形式的新字符串。toLocaleUpperCase()
不会影响输入的字符串本身的值. 大多数情况下,这个方法与 toUpperCase()
会产生相同的值,但是对于一些语言(locale),例如土耳其语,因为它们的大小写映射规则与Unicode默认的映射规则不同,所以调用这两个方法将会产生不同的结果。
例子
使用 toLocaleUpperCase()
'alphabet'.toLocaleUpperCase(); // 'ALPHABET'
'Gesäß'.toLocaleUpperCase(); // 'GESÄSS'
'i\u0307'.toLocaleUpperCase('lt-LT'); // 'I'
let locales = ['lt', 'LT', 'lt-LT', 'lt-u-co-phonebk', 'lt-x-lietuva'];
'i\u0307'.toLocaleUpperCase(locales); // 'I'
Specifications
Specification | Status | Comment |
---|---|---|
ECMAScript 3rd Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.2. |
ECMAScript 5.1 (ECMA-262) String.prototype.toLocaleUpperCase | Standard | |
ECMAScript 2015 (6th Edition, ECMA-262)String.prototype.toLocaleUpperCase | Standard | |
ECMAScript Latest Draft (ECMA-262)String.prototype.toLocaleUpperCase | Draft | |
[ECMAScript Internationalization API 4.0 (ECMA-402) | ||
String.prototype.toLocaleUpperCase](https://tc39.es/ecma402/#sup-string.prototype.tolocaleuppercase) | Draft | ES Intl 2017 added the locale parameter. |