阅读背景:

删除String中的0字节(UTF-8)字符

来源:互联网 

I am currently programming a multi-player game, and I am working on the networking side of it all right now. I have a packet system set up, and the way it works (with Strings at least) is that it takes a number of characters to a maximum of "X" characters. The characters are converted to bytes for sending to the server. If there are less than X characters, then the remaining bytes are set to 0. The issue is that when processing this information on the server and converting it to a string, the 0-byte characters are a '□' in my console, and invisible in my JTextPane. How can I remove all of these 0-byte characters from the String in a clean way? I'd prefer not to have another loop and more variables just to remove the 0-bytes before converting to a String. No one likes dirty-looking code. :pI am currently programming a multi-player game,




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: