Home  >  Article  >  Web Front-end  >  Detailed explanation of how to use javascript to convert letters to upper and lower case

Detailed explanation of how to use javascript to convert letters to upper and lower case

伊谢尔伦
伊谢尔伦Original
2017-07-25 11:42:282743browse

Four js functions are mainly used to implement letter case conversion in js:

1.toLocaleUpperCase
2.toUpperCase
3.toLocaleLowerCase
4. toLowerCase

The following is a simple analysis of these four js functions that implement case conversion.

1.toLocaleUpperCase

Converts all alphabetic characters in the string to uppercase, adapting to the current locale of the host environment.

2.toUpperCase

Converts all letters in the string to uppercase letters.

3.toLocaleLowerCase

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

4.toLowerCase

Convert the letters in the string to lowercase letters.

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

var str='www.php.cn/ABC';
document.write(str.toLowerCase());//将输出 www.php.cn/abc

Or:

document.write('www.php.cn/ABC'.toLowerCase());

We can see that the functions of toLocaleUpperCase and toUpperCase are the same , toLocaleLowerCase and toLowerCase also have the same function, so what is the difference between them?

(1) toLocaleUpperCase toLocaleLowerCase These two functions will adapt to the current locale of the host environment when converting characters in a string. In most cases, the result is the same as using the toUpperCase toLowerCase functions. But if the language rules conflict with regular Unicode case mapping, the results will be different.

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

The above is the detailed content of Detailed explanation of how to use javascript to convert letters to upper and lower case. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn