Javascript: uppercase letters, and javascript English letters

Source: Internet
Author: User

Javascript: uppercase letters, and javascript English letters

Method 1:

Function replaceStr (str) {// Regular Expression str = str. toLowerCase (); var reg =/\ B (\ w) | \ s (\ w)/g; // \ B judge boundary \ s judge space return str. replace (reg, function (m) {return m. toUpperCase ()});} function replaceStr1 (str) {str = str. toLowerCase (); var strTemp = ""; // new string for (var I = 0; I <str. length; I ++) {if (I = 0) {strTemp + = str [I]. toUpperCase (); // The first continue;} if (str [I] = "" & I <str. length-1) {// strTemp + = ""; strTemp + = str [I + 1] after a space. toUpperCase (); I ++; continue;} strTemp + = str [I];} return strTemp;} var text = "abcd ABCD efGH"; console. log (replaceStr (text); // Abcd Efghconsole. log (replaceStr1 (text); // Abcd Efgh

Method 2:

<script type="text\javascript">function ucfirst(str){var str = str.toLowerCase();var strarr = str.split(' ');var result = '';for(var i in strarr){result += strarr[i].substring(0,1).toUpperCase()+strarr[i].substring(1)+' ';}return result;}</script>

Method 3:

<script type="text\javascript">function ucfirst(str) {var str = str.toLowerCase();str = str.replace(/\b\w+\b/g, function(word){  return word.substring(0,1).toUpperCase()+word.substring(1);});return str; </script>

CSS:

The above are the four methods to enable uppercase letters.

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.