This is a very old draft stuck at the bottom of my draft list. lol

[sourcecode language=”javascript”]
var str = "hello world";
str = str.toLowerCase().replace(/b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
alert(str); //Displays "Hello World"
[/sourcecode]

Making it as a function, we can do this.

[sourcecode language=”javascript”]
function capitalize(str) {
return str.toLowerCase().replace(/b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
}
[/sourcecode]

Leave a Reply

%d bloggers like this: