Java string interception example details
Java string interception example details
subject
In Java, the length of the string "ABCD" is the same as that of the string "ab hello", both of which are four characters.
However, the corresponding number of bytes is different. One Chinese character accounts for two bytes.
Define a method to get a substring according to the specified number of bytes.
For example, for "ab hello", if you take three bytes, then the substring is half of AB and "you", then the half will be discarded.
If you take four bytes, it is "ab you", and if you take five bytes, it is still "ab you".
Only GBK and UTF-8 codes are considered
Example code:
If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!