Use String.prototype.replace() to match the first character of each word and String.prototype.toUpperCase() to capitalize it.
} This is a function that capitalizes words in a string. The string is passed in as an argument to the function. The function uses a regular expression to identify words in the string. For each word, the first letter is capitalized and the rest of the letters are converted to lowercase....
Read Next:Capitalize the first letter of each word in a string using JavaScript ✌️ Like this article?Follow me onTwitterandLinkedIn. You can also subscribe toRSS Feed. #JavaScript You might also like... Share it ⟶ I started this blog as a place to share everything I have learned...
Using String.replaceAll() Method Using Apache Commons TextIn this short guide, you will learn how to capitalize the first letter of each word in a string using Java. We have already learned to capitalize the first letter of a string in Java. But capitalizing each word in a string is a ...
This below example will show you, how to capitalize the first letter of a each word in a given string Java. Output:
Capitalize each word of String in Javascript Capitalize first letter of String in Javascript There are multiple ways to Capitalize first letter of String in Javascript. Let’s go through each of them. Using charAt(), toUpperCase() and slice() We will combination of charAt(), toUpperCase() and...
var str = "javascript capitalize string"; var res = str.replace(/wS*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); This code is written in JavaScript. It defines a function that capitalizes the first letter of each word in a string. The fu...
This page shows how to capitalize words in a text string using JavaScript (i.e. change the first letter of each word to upper-case). Place the following code in the document head. This contains the "capitalize" function which does the conversion: ...
JavaScript Code: // Define a function named capital_letter with parameter strfunctioncapital_letter(str){// Split the input string into an array of wordsstr=str.split(" ");// Iterate through each word in the arrayfor(vari=0,x=str.length;i<x;i++){// Capitalize the first letter of ...
Capitalize first letter of a string | JavaScript By: Rajesh P.S.There are number of ways to to capitalize a string to make the first character uppercase. inString[0].toUpperCase() + inString.slice(1); In the above code, uppercases the first character and slices the string to returns...