Use a JavaScript Regular Expression to convert small and medium-sized letters in a string into uppercase and lowercase letters.

Source: Internet
Author: User

**
* Function Description: converts all lowercase letters in a string to uppercase letters.
* Input parameter: string to be converted
* Output: uppercase letter string
* Example: function test_2 (){
* Var STR = "abcdefdsfasdfdsaf ";
* Var result = touppercase (STR );
* Alert (result );
*}
*/

Function touppercase (STR ){
VaR Regexp =/[A-Z]/g;
Return Str. Replace (Regexp, function (smatch ){
Switch (smatch ){
Case 'A ':{
Return "";
Break;
}
Case 'B ':{
Return "B ";
Break;
}
Case 'C ':{
Return "C ";
Break;
}
Case 'D ':{
Return "D ";
Break;
}
Case 'E ':{
Return "E ";
Break;
}
Case 'F ':{
Return "F ";
Break;
}
Case 'G ':{
Return "G ";
Break;
}
Case 'H ':{
Return "H ";
Break;
}
Case 'I ':{
Return "I ";
Break;
}
Case 'J ':{
Return "J ";
Break;
}
Case 'K ':{
Return "K ";
Break;
}
Case 'l ':{
Return "L ";
Break;
}
Case 'M ':{
Return "M ";
Break;
}
Case 'N ':{
Return "N ";
Break;
}
Case 'O ':{
Return "O ";
Break;
}
Case 'p ':{
Return "p ";
Break;
}
Case 'q ':{
Return "Q ";
Break;
}
Case 'r ':{
Return "R ";
Break;
}
Case's ':{
Return "S ";
Break;
}
Case 'T ':{
Return "T ";
Break;
}
Case 'U ':{
Return "U ";
Break;
}
Case 'V ':{
Return "v ";
Break;
}
Case 'W ':{
Return "W ";
Break;
}
Case 'X ':{
Return "X ";
Break;
}
Case 'y ':{
Return "Y ";
Break;
}
Case 'Z ':{
Return "Z ";
Break;
}
}
});
}

 

Tested JavaScript has built-in touppercase () and tolowercase () methods,

Ah, I didn't know how to use the built-in functions in the past. I tried to find implementation methods everywhere. This was collected from the Internet and is indeed available.

Related Article

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.