Home > Web Front-end > JS Tutorial > body text

Detailed explanation of 4 functions for javascript letter case conversion_javascript skills

WBOY
Release: 2016-05-16 16:49:04
Original
2012 people have browsed it

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 of the string to lowercase, taking into account the current locale of the host environment.

4.toLowerCase

Converts 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:

Copy code The code is as follows:

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

or:

Copy code The code is as follows:
document.write('www.jb51.net/ABC'.toLowerCase ());

We can see that toLocaleUpperCase and toUpperCase have the same function, 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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template