Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camel case Validation for String in android

Tags:

java

android

I have a String test="The Mountain view", i need all character after a space in a String need to be in Upper case , for example in the above text 'M' is uppercase after space, the condition need to be reflect for every character after space in String.

I need a regular expression or condition to check all character after space is in Upper case or else i need change the String after space into upper case character if it is in lower case.

If anyone knows means help me out.

Thanks.

like image 571
Karthi Avatar asked Jan 22 '26 09:01

Karthi


1 Answers

There's no need for regular expressions. Try this example, maybe helps:

public class Capitalize {

    public static String capitalize(String s) {
        if (s.length() == 0) return s;
        return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
    }

    public static void main(String[] args) {
        while (!StdIn.isEmpty()) {
            String line = StdIn.readLine();
            String[] words = line.split("\\s");
            for (String s : words) {
                StdOut.print(capitalize(s) + " ");
            }
            StdOut.println();
        }
    }

}
like image 183
evilone Avatar answered Jan 24 '26 22:01

evilone