I want a string entered should be converted to sentence case in whatever case it is.
Like
hi all, this is derp. thank you all to answer my query.
be converted to
Hi all, this is derp. Thank you all to answer my query.
Method 1: Convert String to Title Case in JavaScript Using replace() Method. In JavaScript, the “replace()” method replaces the current string value with the updated one. This method can be used in combination with “toUpperCase()” for converting a string to the title case.
In JavaScript, there are three ways to write a string — they can be written inside single quotes ( ' ' ), double quotes ( " " ), or backticks ( ` ` ).
I came up with this kind of RegExp:
var rg = /(^\w{1}|\.\s*\w{1})/gi;
var myString = "hi all, this is derp. thank you all to answer my query.";
myString = myString.replace(rg, function(toReplace) {
return toReplace.toUpperCase();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With