This paper illustrates the hump-type and hyphen-conversion function of JS. Share to everyone for your reference, specific as follows:
On the Internet to find this paragraph, more like
1. Hump Transfer character:
var s = "Foostylecss";
s = S.replace ([[A-z])/g, "-$1"). toLowerCase ();
Use regular to replace, concise and clear, very good
2. Turn Hump
var S1 = "Foo-style-css";
S1 = S1.replace (//-(/w)/g, function (all, letter) {return
letter.touppercase ();
});
It's not quite clear what this 2 looks.
So I write a, ^_^, this is easy to understand, is the code a bit 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, this time with a regular:
var S1 = "Style-sheet-base";
S1 = S1.replace (//-(/w)/g, function (x) {return X.slice (1). toUpperCase ();});
Haha, interesting.
PS: Here again for you to provide 2 very convenient regular expression tools for your reference to use:
JavaScript Regular expression online test tool:
Http://tools.jb51.net/regex/javascript
Regular expression online generation tool:
Http://tools.jb51.net/regex/create_reg
More readers interested in JavaScript-related content can view the site topics: "JavaScript Replacement Operation Tips Summary", "JavaScript Search Algorithm Skills Summary", "JavaScript data structure and algorithm skills summary", " JavaScript traversal algorithm and tips Summary, "JavaScript in the JSON Operation tips Summary", "JavaScript Error and debugging skills summary" and "JavaScript Mathematical operation Summary"
I hope this article will help you with JavaScript programming.