把下划线式变量转换成驼峰式变量_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 把下划线式变量转换成驼峰式变量

把下划线式变量转换成驼峰式变量

 2014/8/11 12:52:40  youchengLin  程序员俱乐部  我要评论(0)
  • 摘要:packagecom.ways.app.dpca.utils;publicclassTestTransform{publicstaticvoidmain(String[]args){Strings="manf,"+"brand,"+"car_series,"+"old_version_code,"+"model_name,"+"msrp,"+"segment,"+"launch_date,"+"emissions,"+"transmission,"+"year,"+"mon,"+"mix
  • 标签:
class="java" name="code">package com.ways.app.dpca.utils;

public class TestTransform {
	public static void main(String[] args) {
		String s = "manf,"+
       "brand,"+
       "car_series,"+
       "old_version_code,"+
       "model_name,"+
       "msrp,"+
       "segment,"+
       "launch_date,"+
       "emissions,"+
       "transmission,"+
       "year,"+
       "mon,"+
       "mix,"+
       "wholesale,"+
       "avg_tp,"+
       "q1,"+
       "q2,"+
       "q3,"+
       "q4,"+
       "nyear,"+
       "nyear_mix,"+
       "myear,"+
       "myear_mix,"+
       "cumulative_mix,"+
       "definition_price_tier";
		String strArr[] = s.split(",");
		String tempStr = "";
		for(String str:strArr){
			tempStr+=str;
			tempStr+=" as ";
			tempStr+=transform(str)+",";
			tempStr+="\n";
		}
		System.out.println(tempStr);
	}
	
	public static String transform(String str){
		while(str.contains("_")){
			int i = str.indexOf("_");
			if(i+1<str.length()){
				char c = str.charAt(i+1);
				String temp = (c+"").toUpperCase();
				str = str.replace("_"+c, temp);
			}
		}
		return str;
	}
}

?

  • 相关文章
发表评论
用户名: 匿名