可以使用正则表达式替换方法 replaceAll(),将所有的 � 替换为空字符串即可。

示例代码:

String str = "hello�world�";
String result = str.replaceAll("�", "");
System.out.println(result); // 输出:hello world

在正则表达式中,� 都是特殊字符,需要使用反斜杠进行转义,因此需要将其写成 � 的形式。replaceAll() 方法会返回一个新的字符串,原字符串不会改变。

java 正则 去除字符串中所有 �

原文地址: https://www.cveoy.top/t/topic/cg5x 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录