You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
897 B
Java
28 lines
897 B
Java
5 years ago
|
package com.jingcheng.template.service.impl;
|
||
|
|
||
|
import java.io.UnsupportedEncodingException;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
public class Test {
|
||
|
public static void main(String[] args) {
|
||
|
String a = "啊啊啊啊啊啊啊啊啊啊啊啊:2123啊阿德dadadada";
|
||
|
String b = getStringByEnter(10,a);
|
||
|
System.out.println(b);
|
||
|
}
|
||
|
|
||
|
public static String getStringByEnter(int length, String string) {
|
||
|
for (int i = 1; i <= string.length(); i++) {
|
||
|
try {
|
||
|
if (string.substring(0, i).getBytes("GBK").length > length) {
|
||
|
return string.substring(0, i - 1) + "\n" +
|
||
|
getStringByEnter(length, string.substring(i - 1));
|
||
|
}
|
||
|
} catch (UnsupportedEncodingException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
return string;
|
||
|
}
|
||
|
}
|