package com.jingsong.bug;
public class SpaceBug {
public static void main(String[] args) {
char[] chars1 = new char[]{'h', 'e', 32, 'l', 'l', 32, 'o'};
String s1 = new String(chars1);
System.out.println(s1);
System.out.println(s1.replaceAll(" ", ""));
System.out.println();
char[] chars2 = new char[]{'h', 'e', 32, 'l', 'l', 130, 'o'};
String s2 = new String(chars2);
System.out.println(s2);
System.out.println(s2.replaceAll(" ", ""));
System.out.println();
String s3 = forceTrim(s2);
System.out.println(s3);
}
public static String forceTrim(String target) {
char[] chars = target.toCharArray();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < chars.length; i++) {
if (chars[i] == 32 || chars[i] == 130) {
continue;
}
sb.append(chars[i]);
}
return sb.toString();
}
}