Four js functions are mainly used to implement letter case conversion in js:
1.toLocaleUpperCase
2.toUpperCase
3. toLocaleLowerCase
4. toLowerCase
Below is a simple analysis of these four js functions that implement case conversion one by one.
1.toLocaleUpperCase
All alphabetical characters in the string will be converted to uppercase while adapting to the current locale of the host environment.
2.toUpperCase
Convert all letters in the string into capital letters.
3. toLocaleLowerCase
Convert all alphabetical characters of the string to lowercase, taking into account the current locale of the host environment.
4. toLowerCase
Convert letters in the string to lowercase letters.
The usage of the above four functions is basically the same. Here is an example using toLowerCase:
The code copy is as follows:
var str='www.VeVB.COM/ABC';
document.write(str.toLowerCase());//The output www.VeVB.COM/abc
or:
The code copy is as follows: document.write('www.VeVB.COM/ABC'.toLowerCase());
We can see that the functions of toLocaleUpperCase and toUpperCase are the same, and toLocaleLowerCase and toLowerCase also have the same functions. So what is the difference between them?
(1) ToLocaleUpperCase toLocaleLowerCase These two functions will adapt to the current locale settings of the host environment when converting characters in the string. In most cases, the result is the same as the result obtained by using the toUpperCase toLowerCase functions. But if the language rules conflict with the regular Unicode case mapping method, the result will be different.
(2) The toUpperCase toLowerCase method does not convert non-alphabetical characters in the string.