String output = StringUtils.capitalize(INPUT); assertEquals(EXPECTED, output); The test passes if we execute it. As we can see, we simply callStringUtils.capitalize(INPUT).Then the library does the job for us. It’s worth mentioning thattheStringUtils.capitalize()method is null-safe and works...
Using String.substring() Method The simplest way to capitalize the first letter of a string in Java is by using the String.substring() method: String str = "hello world!"; // capitalize first letter String output = str.substring(0, 1).toUpperCase() + str.substring(1); // print the ...
Matcher; import java.util.regex.Pattern; public class Main{ public static String capitalize(final String word) { if (word.length() > 1) { return String.valueOf(word.charAt(0)).toUpperCase() + word.substring(1); }//from w w w .java2 s .co m return word; } } ...
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 ...
There is a number of ways to capitalize the first letter of the string in JavaScript. For example: "this is an example"->"This is an example" "the Atlantic Ocean"->"The Atlantic Ocean" ThetoUpperCase()method transforms all letters in a string to uppercase; we will use it in com...
To capitalize the first letter in a string is easy if you undertake some steps.First of all you should get the first letter of the string by setting the charAt() method at 0 index:Javascript charAt method1 2 let string = "w3docs.com"; console.log(string.charAt(0)); // Returns...
A simple package to capitalize the first character of a string. Latest version: 1.0.7, last published: 2 months ago. Start using capitalize-first-letter-string in your project by running `npm i capitalize-first-letter-string`. There are no other projects
capitalize the first letter of a stringCharles Dupont
Capitalize-First-Letter-Of-String--npm 将字符串的第一个字母转换为大写字母。 仅支持字符串值,将返回任何其他类型的空字符串。 Installtion npm install--save capitalizefirstletterofstring Usage varCapitalizeFirstLetterOfString=require('capitalizefirstletterofstring');CapitalizeFirstLetterOfString(null)//=> ...
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...