简体   繁体   中英

How to convert lower case character into upper case after each special character present in the String?

Need to change character from lower case into upper case after each special character present in the string.

i tried using indexOf("_") +1 and get the posstion in the string and tried but no luck

If my input string values is = "java_compiler_code_example"

then i am expecting = java_Compiler_Code_Example

After each special character "_" i wanted to change that character from lower case into upper case.

Try this. It will take your sample String split it on the separtar , go through and uppercase each word after the first the combined them back and return it.

public String cammelCase(String sampleString, String separator) {
  String[] split = sampleString.split(separator);

  if (split.length < 2) return sampleString;

  for (int i =  1; i < split.length; i++) {
   split[i] = split[i].substring(0,1).toUpperCase() + split[i].substring(1);
  }

  String retStr = "";
  for (int i =0; i < split.length; i++) {
    resStr += split[i];
    if (i != split.length - 1) {
      retStr += separator;
     }
  }
 return retStr;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM