publicclassFirstLetterUpperCase{publicstaticvoidmain(String[]args){Stringstr="hello";StringfirstLetter=str.substring(0,1).toUpperCase();StringrestOfString=str.substring(1);Stringresult=firstLetter+restOfString;
Another idea to solve the problem is to useregex(“^.“) to match the first character and convert the matched group to upper case. It wasn’t an easy task before Java 9. This is becauseMatcher‘s replacement methods, such asreplaceAll()andreplaceFirst(),don’t support aFunctionobject or ...
Let's say I want to make the h in the above string to uppercase. I could do that by selecting the first letter of the string, converting it to uppercase, and concatenating the capitalized letter with the rest of the string. const capitalizedMessage = message.charAt(0).toUpperCase() + ...
publicclassMain{publicstaticvoidmain(String[]args){Stringstr="hello world";StringfirstLetter=str.substring(0,1);// 获取首字母StringcapitalizedStr=firstLetter.toUpperCase()+str.substring(1);// 将首字母大写并拼接剩余字符System.out.println(capitalizedStr);// 输出"Hello world"}} 1. 2. 3. 4. 5...
JavaScript provides several built-in methods for manipulating strings, including one called toUpperCase() which can be used to convert the first letter of a string to uppercase.
How do I make the first letter of a string uppercase, but not change the case of any of the other letters? For example: "this is a test"->"This is a test" "the Eiffel Tower"->"The Eiffel Tower" "/index.html"->"/index.html" ...
However, there are methods available to change the case of the string (uppercase, lowercase, etc.). 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...
The easiest way to capitalize the first character of each word of a string is by using Java 8 Stream API:String str = "welcome to java"; // uppercase first letter of each word String output = Arrays.stream(str.split("\\s+")) .map(t -> t.substring(0, 1).toUpperCase() + t....
js uppercase the first letter of string js String.toUpperCase `-webkit-border-image`.split(`-`).filter(i=>i !=="").reduce((acc, i) =>acc += i)// "webkitborderimage"`-webkit-border-image`.split(`-`).filter(i=>i !=="").reduce((acc, i) =>acc += i[0].toUpperCase() +...
*@return*/publicstaticString makeFirstLetterUpperCase(String newStr) {if(newStr.length() == 0)returnnewStr;char[] oneChar =newchar[1]; oneChar[0] = newStr.charAt(0); String firstChar=newString(oneChar);return(firstChar.toUpperCase() + newStr.substring(1)); ...