Make the next symbol of space as capital

Possible duplicate:
Title First Char of each word in string Java

I have a string "abc def ghi", I want to make it like "abc def ghi". Similarly, I also have a type string "abc def", and I want to make it "abc def". In java how is this possible

+3
source share
3 answers
System.out.println(
  org.apache.commons.lang.WordUtils.capitalize(
    "yellow fox jumped over brown foot"
  )
);

output:

Yellow Fox Jumped Over Brown Foot
+2
source

You can use the capitalize method from the ACL class of WordUtils.

+2
source

This may not be the most effective, but it may give you a starting point:

public String capitalize(String original) {
        String[] parts = original.split(" ");

        StringBuffer result = new StringBuffer();

        for (String part : parts) {
            String firstChar = part.substring(0, 1).toUpperCase();
            result.append(firstChar + part.substring(1));
            result.append(" ");
        }

        String capitalized = result.toString();

        return capitalized.substring(0, capitalized.length()-1);
}
0
source

Source: https://habr.com/ru/post/1770872/


All Articles