开发者

Camel case Validation for String in android

开发者 https://www.devze.com 2023-03-22 08:13 出处:网络
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 t

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 cas开发者_JAVA百科e.

If anyone knows means help me out.

Thanks.


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();
        }
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消