public static String[] splitStr(String str, int splitLen) {
int count = str.length() / splitLen + (str.length() % splitLen == 0 ? 0 : 1);
String[] strs = new String[count];
for (int i = 0; i < count; i++) {
if (str.length() <= splitLen) {
strs[i] = str;
} else {
strs[i] = str.substring(0, splitLen);
str = str.substring(splitLen);
}
}
return strs;
}
[Java]将一个字符串按照指定字符数进行分割
最新推荐文章于 2024-06-30 03:14:03 发布