public static void main(String[] args) {
String dispatchSite = "差不奥xxcnubis那里是身材好cU币a我吃完子额鹅湖撤回";
String str = subGB2312(dispatchSite, 30);
System.out.println(str);
str = sub(dispatchSite, 30);
System.out.println(str);
str = subStringFix(dispatchSite, 30);
System.out.println(str);
}
//二分查找 适合一切特殊字符(GB2312或GBK都可)
public static String subGB2312(String source, int target) {
String targetStr = "";
try {
int length = source.getBytes("GB2312").length;
if (length > target) {
int index = 0;
int left = 0;
int right = target;
if (target >= source.length()
如何截取中英文字符串不乱码
最新推荐文章于 2024-07-16 11:13:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)