贴出我自己写的代码(没写注释楼主可以参考参考很简单的):
/**
* @param args
*/
public static void main(String[] args) {
String s ="we are at the b2b web";
String pp = "";
ArrayList al = new ArrayList();
String t = "";
s = s.replace(" ", "*") + "*";
for (int i = 1; i < s.length(); i++) {
char im = s.substring(i - 1, i).charAt(0);
char in = s.substring(i, i + 1).charAt(0);
if ((in <= '9' && in >= '0' && im >= 'a' && im <= 'z')
|| (im <= '9' && im >= '0' && (in >= 'a' && in <= 'z'))) {
pp += s.substring(i - 1, i) + "_";
} else {
pp += s.substring(i - 1, i);
}
}
pp = pp + "*";
for (int i = 0; i < pp.length(); i++) {
if (pp.substring(i, i + 1).equals("*")) {
al.add(t);
t = "";
continue;
} else {
t += pp.substring(i, i + 1);
}
}
for (int i = 0; i < al.size(); i++) {
if (al.get(i) != "")
System.out.print(al.get(i).toString().substring(0, 1)
.toUpperCase()
+ al.get(i).toString().substring(1) + " ");
}
} |