Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String s = "user_nick_name";
- // build result in a StringBuilder
- StringBuilder result= new StringBuilder();
- for (int pos=0; pos<s.length(); pos++)
- { // iterate through input
- char c= s.charAt(pos);
- if (c!='_') // if not _ just append char unaltered
- result.append(c);
- else
- {
- // is there a next char?
- if (pos==s.length()-1) break; // no, so _ was a final char
- // get next char
- char cNext=s.charAt(pos+1);
- // convert to upper case and append
- result.append(Character.toUpperCase(cNext));
- pos++;
- }
- }
- s=new String(result); // back to a String
- System.out.println(s);
Advertisement
Add Comment
Please, Sign In to add comment