Is there any equivalent to String.strip() in android, except trim()?
My development environments are Java11, minSdk24, targetSdk31 and compileSdk31. Is that possible to make String.strip() available if I upgrade one of them?
Is there any equivalent to String.strip() in android, except trim()?
My development environments are Java11, minSdk24, targetSdk31 and compileSdk31. Is that possible to make String.strip() available if I upgrade one of them?
You can try upgrading your project to use Java 11, which has the function. Or write it yourself, its trivial.
public static String strip(String value) {
int firstChar = 0;
while (firstChar < value.length() && Character.isWhitespace(value.charAt(firstChar))) {
firstChar++;
}
int lastChar = value.length() - 1;
while (lastChar > firstChar && Character.isWhitespace(value.charAt(lastChar))) {
lastChar--;
}
return value.substring(firstChar, lastChar + 1);
}