Example of getting started with the toUpperCase method of a JavaScript string object (used to convert letters into uppercase) and touppercase

Source: Internet
Author: User

Example of getting started with the toUpperCase method of a JavaScript string object (used to convert letters into uppercase) and touppercase

JavaScript toUpperCase Method

The toUpperCase method is used to convert (English) strings into uppercase and return the converted strings. The syntax is as follows:

Copy codeThe Code is as follows:
Str_object.toUpperCase ()

ToUpperCase method example

Copy codeThe Code is as follows:
<Script language = "JavaScript">

Var str = "AaBbCc ";
Document. write (str. toUpperCase ());

</Script>

Run this example and output:

Copy codeThe Code is as follows:
AABBCC

ToLocaleUpperCase Method

The toLocaleUpperCase method is basically the same as the toUpperCase method. toLocaleUpperCase converts the string to uppercase according to the local method. Only a few languages (such as Turkish) have local-specific case ing.


In JavaScript, how can I convert uppercase letters in strings to lowercase letters and convert lowercase letters to uppercase letters?

Example:
Function funZhuanHuanDaXiaoXie (str)
{
Var ar = str. split ('');
For (var I = 0; I <ar. length; I ++)
{
If (ar [I]. charCodeAt (0)> = 65 & ar [I]. charCodeAt (0) <= 90)
{
Ar [I]. toLowerCase ();
}
Else
{
Ar [I]. toUpperCase ();
}
} // All conversions have been made here;
Str = "";
For (var I = 0; I <ar. length; I ++)
{
Str + = ar [I];
}
Reture str;
}

The landlord can use the method I wrote to convert it, for example:
Var text = "IUHIUUskuisudin ";

Call this method conversion (you can set the method name as you like ):

Text = funZhuanHuanDaXiaoXie (text );

Java uses the toUpperCase () and toLowerCase () Methods of the String class to convert the case sensitivity of strings.

If it is for this specific string, it is easy to do.
First
String str = "ABCdef ";
String str1 = str. subString (3 );
String str2 = str. subString (3,6 );
Str = str1.toLowerCase () + str2.toUpperCase ();

If it is an arbitrary string, it needs to be converted into a character array using string. tochararray (). Then compare the data according to the ascII value.
Then convert according to the rule!

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.