waltermilner

Untitled

Dec 13th, 2014
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1.     String s = "user_nick_name";
  2.     // build result in a StringBuilder
  3.     StringBuilder result= new StringBuilder();
  4.     for (int pos=0; pos<s.length(); pos++)
  5.     { // iterate through input
  6.         char c= s.charAt(pos);
  7.         if (c!='_') // if not _ just append char unaltered
  8.             result.append(c);
  9.         else
  10.         {
  11.             // is there a next char?
  12.             if (pos==s.length()-1) break; // no, so _ was a final char
  13.             // get next char
  14.             char cNext=s.charAt(pos+1);
  15.             // convert to upper case and append
  16.             result.append(Character.toUpperCase(cNext));
  17.             pos++;
  18.         }
  19.     }
  20.     s=new String(result); // back to a String
  21.     System.out.println(s);
Advertisement
Add Comment
Please, Sign In to add comment