Analysis of the conversion functions of the camper and character types implemented by JS, and js implements the camper
The examples in this article describe how to use JavaScript to convert camps and hyphens. We will share this with you for your reference. The details are as follows:
I like this online section.
1. Camping to hyphen:
Var s = "fooStyleCss"; s = s. replace (/([A-Z])/g, "-$1 "). toLowerCase (); // Replace with regular expressions, which is concise and clear.
2. camper
var s1 = "foo-style-css";s1 = s1.replace(//-(/w)/g, function(all, letter){ return letter.toUpperCase();});
This section 2 is not very clear.
Write one by yourself, ^ _ ^, which is easy to understand, that is, the Code is a little more;
var s = "style-sheet-base";var a = s.split("-");var o = a[0];for(var i=1;i<a.length;i++){ o = o + a[i].slice(0,1).toUpperCase() + a[i].slice(1);}
Write another record. This time, use the regular expression:
var s1 = "style-sheet-base";s1 = s1.replace(//-(/w)/g, function(x){return x.slice(1).toUpperCase();});
Haha, interesting
PS: here we will provide two very convenient Regular Expression tools for your reference:
JavaScript Regular Expression online testing tool:
Http://tools.jb51.net/regex/javascript
Regular Expression generation tool:
Http://tools.jb51.net/regex/create_reg