如何檢查字節數組中的字節是否是Unicode字符?檢查字節數組中的字節是否爲Unicode
主要probleme:
android 4.2 new String(bytes) remove unicode chars from my String: [\uFFFD]
我需要解決類似的問題。
如何檢查字節數組中的字節是否是Unicode字符?檢查字節數組中的字節是否爲Unicode
主要probleme:
android 4.2 new String(bytes) remove unicode chars from my String: [\uFFFD]
我需要解決類似的問題。
return Charset.forName("UTF-8").newEncoder().canEncode(string);
更新:您沒有通過Charset
到new String(bytes)
,所以它只是假設你正在使用的默認字符集。相反,例如, new String(bytes, "UTF-8")
。
不,不是真的。例如,您可以通過觀察字節數組中的字符不違反UTF-8規則來猜測。有關更多信息,請參閱http://blogs.msdn.com/b/oldnewthing/archive/2007/04/17/2158334.aspx。
你知道一個unicode字符可以在幾個字節上編碼,對吧? – etienne
是啊我知道 – lacas
我們在談論UTF-8,UTF-16或UTF-32嗎? – luiscubal