JAVA去除ASCLL码为160的空格

来源:互联网 发布:加工中心钻孔手动编程 编辑:程序博客网 时间:2024/05/21 11:30

问题描述

读入一串字符串,输出的时候出现’?’字符。通过Debug模式检查字符串,发现字符串中该位置的ASCLL值为160

测试程序

String input = "12121·121";input += (char)160+"";input = input.replaceAll("\\s+", " ");input = input.trim();System.out.println(Arrays.toString(input.split(" ")));

测试结果

字符串中存在ASCLL为160的空格,并且该空格不能通过replace \s 以及trim的方法去除。

解决方案

通过 下面的代码可以去除

replaceAll("[\\u00A0]+", "")

参考

http://www.programgo.com/article/41803297208/
http://www.iteye.com/topic/1133417

0 0