码迷,mamicode.com
首页 > 编程语言 > 详细

java字符串根据正则表达式让单词首字母大写

时间:2018-05-31 16:13:40      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:class   ==   bst   正则   rgs   sys   main   cas   public   

public class Da {
public static void main(String[] args) {
String s = "hello_*java_*world";
System.out.println("转化前:"+s);
String[] strs = s.split("_\\*");
String ret = "";
for(int i = 0; i < strs.length; i++){
if (i == (strs.length-1)){
ret = ret + strs[i].substring(0, 1).toUpperCase() + strs[i].substring(1, strs[i].length());
}else{
ret = ret + strs[i].substring(0, 1).toUpperCase() + strs[i].substring(1, strs[i].length())+ "_*";
}
}
System.out.println("转化后:"+ret);
}
}

java字符串根据正则表达式让单词首字母大写

标签:class   ==   bst   正则   rgs   sys   main   cas   public   

原文地址:https://www.cnblogs.com/THEONLYLOVE/p/9117139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!