关于java中string的处理
有一字符串是这样的:String str1="abc中国123@";我想将这样的字符串转换成:String str2="abc123"也就是说,转换后的字符串只要“字母”和“数字”,求一方法. --------------------编程问答-------------------- String str = "abc中国123@";str = str.replaceAll("[^\\w]", ""); --------------------编程问答-------------------- String str = "abc中国123@";
StringBuffer buffer = new StringBuffer();
for(int i = 0; i < str.length(); i++) {
String temp = str.charAt(i) + "";
if(temp.matches("[\\w]") || temp.matches("[\\d]")) {
buffer.append(temp);
}
}
System.out.println(buffer.toString()); --------------------编程问答-------------------- 运用正则表达式了 --------------------编程问答--------------------
+1 --------------------编程问答--------------------
+1 --------------------编程问答--------------------
补充:Java , Web 开发