Android : How To Remove White Spaces In Chinese Characters?
Solution 1:
Chinese and Japanese don't use the regular space character ' '. The languages use their own that is the same width as the characters. This is the character here ' ', you should write a manual trim function to check for that character at the beginning and end of the string.
You may be able to directly use the character if you convert your code file to unicode (if java will allow). Otherwise you will need to find the unicode character code for ' ' and check if the character code is at the beginning or end of the string.
The following link tells us that the ideographic space is 0xe38080 in UTF-8 and 0x3000 in UTF-16, and that Java's Character.isSpaceChar() function will return true. I would have thought String.trim() would have used this property to determine whether or not to trim though.
Solution 2:
You can use Googles Guava library for this;
CharMatcher.inRange('\0', ' ').trimFrom(str);
you can refer more about this here:
Solution 3:
To trim whitespaces in unicode which is having 2 byte use string replace.
replace 2byte space with 1byte space. 0x3000 is the hexadecimal value of unicode IDEOGRAPHIC SPACE
String.replace("\u3000"," ").trim()
Post a Comment for "Android : How To Remove White Spaces In Chinese Characters?"