/**
* @Author: Lang
* @Date: 2018/5/2 14:10
* @Description: 去除unicode为12288字符为全角空格(trim()无法去除),与一般空格
* @param str
* @return: java.lang.String
*/
public static String fullwidthSpaces(String str){
if (str != null && !" ".equals(str)){
return str.replace((char) 12288, ' ').replaceAll(" ", "");
}else{
return "";
}
}
测试:
public static void main(String[] args) {
String str = "http://apis.map.qq.com/ws/geocoder/v1/?address= 广东省广州大道南彩棕街2 号";
System.out.println((int)str.charAt(61));//index 61 位全角空格
// '\0' 为空字符
String trim = str.replace((char) 12288,'\0').replaceAll(" ","");
System.out.println(trim);
}
控制台: