一段有意思的小代码,忘了从哪里弄来的,做数据库映射可能用到
package abc;
public class StringUtil {
/**
* 首字母大写
*
* @param srcStr
* @return
*/
public static String firstCharacterToUpper(String srcStr) {
return srcStr.substring(0, 1).toUpperCase() + srcStr.substring(1);
}
/**
* 替换字符串并让它的下一个字母为大写
*
* @param srcStr
* @param org
* @param ob
* @return
*/
public static String replaceUnderlineAndfirstToUpper(String srcStr, String org, String ob) {
String newString = "";
int first = 0;
while (srcStr.indexOf(org) != -1) {
first = srcStr.indexOf(org);
if (first != srcStr.length()) {
newString = newString + srcStr.substring(0, first) + ob;
srcStr = srcStr.substring(first + org.length(), srcStr.length());
srcStr = firstCharacterToUpper(srcStr);
}
}
newString = newString + srcStr;
return newString;
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(replaceUnderlineAndfirstToUpper("ni_hao_abc", "_", ""));
}
}