Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ini untuk merubah string ke frmat Xxxxxx Xxxxxx, Uppercase di awal kalimat ( by : hanif method )
- public static String capitalize(String text) {
- char[] stringArray = text.trim().toCharArray();
- boolean wordStarted = false;
- for( int i = 0; i < stringArray.length; i++) {
- char ch = stringArray[i];
- if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '\'') {
- if( !wordStarted ) {
- stringArray[i] = Character.toUpperCase(stringArray[i]);
- wordStarted = true;
- }else{
- stringArray[i] = Character.toLowerCase(stringArray[i]);
- wordStarted = true;
- }
- } else {
- wordStarted = false;
- }
- }
- return new String(stringArray);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement