java 去除特殊Unicode编码
时间: 2023-11-17 14:04:19 浏览: 241
java二维数组删除特定行代码
5星 · 资源好评率100%
要在Java中去除特殊Unicode编码,可以使用正则表达式的replaceAll方法。首先,根据参考文献的思路,可以使用以下代码来去除Unicode编码的空格:
```java
private String repSpace(String src){
return src.replaceAll("[\\pZ]", "");
}
```
其中,`\\pZ`表示Unicode属性中的分隔符,包括空格等。这样,可以将字符串中的特殊Unicode编码的空格去除掉。
另外,如果要限制Unicode编码的区间来过滤掉区间外的字符,可以使用以下代码:
```java
public static String range = "0000-007F;2E80-2EFF;3000-303F;3400-4DBF;4E00-9FBF;F900-FAFF";
public static boolean unicodeRange(String str) {
String[] ranges = range.split(";");
char[] chars= str.toCharArray();
for (char c : chars) {
int flag = 0;
for (String s : ranges) {
String[] compare = s.split("-");
if (c >= Integer.parseInt(compare<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Java通过Unicode编码过滤特殊字符](https://blog.csdn.net/dsh153/article/details/107363908)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [Java去掉Unicode特殊字符](https://blog.csdn.net/pang9998/article/details/101169998)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文