简体   繁体   中英

How to identified given string is double byte characterset using java?

I want to Identify given string is double byte character set or not, using java?

Thanks

A String does not have a character set property, in fact, it is always UTF-16 (16 bit used for each char).

If you wanted to try to discover the likely charset of some input data (eg in a file or stream), then the ICU4J CharsetDetector could be used.

But by the time the data is in a String in your code, it is too late.

Your string has multibyte characters if String.codePointCount(int beginIndex, int endIndex) for the whole text range will give not zero result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM