Java 正则表达式去除字符串中的特殊字符 �
可以使用正则表达式替换方法 'replaceAll()',将所有的 '�' 替换为空字符串即可。
示例代码:
String str = 'hello�world�';
String result = str.replaceAll('�', '');
System.out.println(result); // 输出:hello world
在正则表达式中,'' 和 '�' 都是特殊字符,需要使用反斜杠进行转义,因此需要将其写成 '�' 的形式。'replaceAll()' 方法会返回一个新的字符串,原字符串不会改变。
原文地址: https://www.cveoy.top/t/topic/nshd 著作权归作者所有。请勿转载和采集!