As we can see, we only want the first character, ‘h‘, to be changed into ‘H‘. However,the remaining characters shouldn’t be modified. Of course, if the input string is empty, the result should be an empty string too: String EMPTY_INPUT = ""; String EMPTY_EXPECTED = ""; In ...
capitalize the first letter in string Demo Codeimport java.util.regex.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); }//...
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 string System.out.println(output...
Capitalize first letter of each word Capitalize first letter of String Here are the steps to convert first letter of string to uppercase in java Get first letter of String firstLetStr using str.substring(0,1). Get remaining String remLetStr using str.substring(1). Convert first letter of ...
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 ...
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...
JavaScriptJavaScript String Video Player is loading. Current Time0:00 / Duration-:- Loaded:0% 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" ...
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 slice() functions to capitalize first letter...
Capitalize the First Letter of a String in C++ We will deal with this problem in three different cases: The string begins with an alphabet. The string starts with a special character or a number. The string contains a multibyte starting character, and we need to capitalize each word. ...
# python program to capitalizes the # first letter of each word in a string # function def capitalize(text): return ' '.join(word[0].upper() + word[1:] for word in text.split()) # main code str1 = "Hello world!" str2 = "hello world!" str3 = "HELLO WORLD!" str4 = "...