------- <a href="
http://www.itheima.com" target="blank">android培训</a>、<a href="
http://www.itheima.com" target="blank">java培训</a>、期待与您交流! ----------
需求有一个字符串"我我。。。。要要。。。学学。。。学编。。。。编编。。。程程程!"
编写程序去除重复的字符和中间的非汉字
代码如下
String string="我我。。。。要要。。。学学。。。学编。。。。编编。。。程程程!";
需求有一个字符串"我我。。。。要要。。。学学。。。学编。。。。编编。。。程程程!"
编写程序去除重复的字符和中间的非汉字
代码如下
String string="我我。。。。要要。。。学学。。。学编。。。。编编。。。程程程!";
System.out.println(string);
String reg="。+";//定义规则
string=string.replaceAll(reg, "");//去除。
//System.out.println(string);
reg="(.)\\1+";//定义规则
string=string.replaceAll(reg, "$1");//去除重复的字
System.out.println(string);//输出结果
本文介绍了一种通过正则表达式去除字符串中重复字符的方法,并演示了如何移除非汉字字符,最终实现对字符串的简化。

1911

被折叠的 条评论
为什么被折叠?



