SoFunction
Updated on 2025-04-07

Introduction to the definition and usage method in jsp


<%!
String splitString(String str, int a) {
if (str != null && ().length() > 0 && a > 0) {
// Get the byte length of the string
int length = ().length;
// All Chinese characters are not included
if (() == length) {
// If the intercept length is within the string length, substring, otherwise take this string
if (a < ()) {
return (0, a);
} else {
return str;
}
} // Contains Chinese characters
else {
StringBuffer sb = new StringBuffer();
// Intercept algorithm traverses the string and monitors the a value
for (int i = 0; i < () && a > 0; i++) {
// If it is Chinese characters, calculate 2 lengths.
if ((i) >= '\u4e00' && (i) <= '\u9fa5') {
// If it is a Chinese character and is not the last character, add it, otherwise it will not be added
if (a > 1) {
((i));
a -= 2;
}
// Not Chinese characters only count as one length
} else {
((i));
a--;
}
}
return ();
}
}
return "Input is incorrect";
}

%>