Javascript letter case conversion of 4 functions

  • 2020-03-30 02:52:19
  • OfStack

Js to achieve letter case conversion mainly used four js functions:

1. ToLocaleUpperCase
2. The toUpperCase
3. ToLocaleLowerCase
4. ToLowerCase

The following four case conversion js functions to do a simple analysis.

1. ToLocaleUpperCase

Converts all alphanumeric characters in a string to uppercase while accommodating the current locale of the host environment.

2. The toUpperCase

Converts all letters in a string to uppercase.

3. ToLocaleLowerCase

Converts all alphabetic characters of the string to lowercase, taking into account the current locale of the host environment.

4. ToLowerCase

Converts a letter in a string to lowercase.

The usage of the above four functions is basically the same. The following is just an example of toLowerCase:


var str='www.jb51.net/ABC';
document.write(str.toLowerCase());// The output  www.jb51.net/abc

Or:

document.write('www.jb51.net/ABC'.toLowerCase());

We can see that toLocaleUpperCase and toUpperCase both have the same function, and toLocaleLowerCase and toLowerCase have the same function, so what's the difference between them?

(1) toLocaleUpperCase toLocaleLowerCase these functions will adapt to the current locale of the host environment while converting characters in a string. In most cases, the result is the same as with toUpperCase toLowerCase. However, if the language rules conflict with the normal Unicode case mapping, the result will be different.

(2) the toUpperCase toLowerCase method does not convert non-alphabetic characters in the string.


Related articles: