且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android:如何删除汉字中的空格?

更新时间:2023-01-31 07:54:19

中文和日文使用常规空格字符。这些语言使用自己的,与字符相同的宽度。这是这里的字符,你应该写一个手动修剪函数来检查字符串的开头和结尾处的那个字符。

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.

你可以直接如果您将代码文件转换为unicode(如果java将允许)使用字符。否则,您将需要找到''的unicode字符代码,并检查字符代码是否在字符串的开头或结尾。

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.

以下链接告诉我们,表意空间在UTF-8中为0xe38080,在UTF-16中为0x3000,并且Java的Character.isSpaceChar()函数将返回true。我会认为String.trim()将使用这个属性来确定是否修剪。

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.

http://www.fileformat.info/info/unicode/char/3000/index.htm