Java如何将每个单词的第一个字符转为大写
2个回答
2018-05-28
展开全部
package com.yiibai;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MakeFirstLetterUppercase {
public static void main(String[] args) {
String str = "this is a java test String upcase: 123string";
System.out.println(str);
StringBuffer stringbf = new StringBuffer();
Matcher m = Pattern.compile("([a-z])([a-z]*)", Pattern.CASE_INSENSITIVE).matcher(str);
while (m.find()) {
m.appendReplacement(stringbf, m.group(1).toUpperCase() + m.group(2).toLowerCase());
}
System.out.println(m.appendTail(stringbf).toString());
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MakeFirstLetterUppercase {
public static void main(String[] args) {
String str = "this is a java test String upcase: 123string";
System.out.println(str);
StringBuffer stringbf = new StringBuffer();
Matcher m = Pattern.compile("([a-z])([a-z]*)", Pattern.CASE_INSENSITIVE).matcher(str);
while (m.find()) {
m.appendReplacement(stringbf, m.group(1).toUpperCase() + m.group(2).toLowerCase());
}
System.out.println(m.appendTail(stringbf).toString());
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询