黑马程序员技术交流社区

标题: 关于java中String的处理 [打印本页]

作者: chuanyueing    时间: 2013-2-4 17:17
标题: 关于java中String的处理
有一字符串是这样的:String str1="abc中国123@";我想将这样的字符串转换成:String str2="abc123"也就是说,转换后的字符串只要“字母”和“数字”,求一方法。
作者: Gaara    时间: 2013-2-4 17:28
本帖最后由 张文彬 于 2013-2-4 17:43 编辑

class StringTest
{
public static void main(String[] args)
{
  String str1="abc中国123@";
  String str2 = str1.replaceAll("[^a-zA-Z0-9]", ""); //邮箱正则表达式
  System.out.println(str2);
}
}


作者: chuanyueing    时间: 2013-2-4 17:51
张文彬 发表于 2013-2-4 17:28
class StringTest
{
public static void main(String[] args)

:hug:thanks





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2