4 functions for JavaScript letter case Conversion _javascript Tips

Source: Internet
Author: User
Tags locale alphanumeric characters

JS in the implementation of the letter case conversion is mainly used in four JS functions:

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

The following is a simple analysis of these four JS functions for case conversion.

1.toLocaleUpperCase

Converts all alphabetic characters in a string to uppercase and adapts to the current locale of the host environment.

2.toUpperCase

Converts all letters in a string to uppercase letters.

3.toLocaleLowerCase

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

4.toLowerCase

Converts letters in a string to lowercase letters.

The usage of the above four functions is basically the same, the following is illustrated with toLowerCase examples:

Copy Code code as follows:

var str= ' Www.jb51.net/ABC ';
document.write (Str.tolowercase ());//Will output WWW.JB51.NET/ABC

Or:

Copy Code code as follows:
document.write (' Www.jb51.net/ABC '. toLowerCase ());

We can see that tolocaleuppercase and toUpperCase functions are the same, tolocalelowercase and tolowercase are the same function, then what is the difference between them?

(1) toLocaleUpperCase tolocalelowercase These two functions, when converting characters in a string, are adapted to the host environment's current locale. In most cases, the result is the same as the result of the use of toUpperCase tolowercase the two functions. However, if the language rules conflict with the normal Unicode case mapping, the results will be different.

(2) The toUpperCase toLowerCase method does not convert non-alphanumeric characters in strings.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.