oder die normale Trim Methode abgeändert:
Code:
/** Links trim */
public static String trimLeft(final String s){
return trim(s, true);
}
/** Rechts trim */
public static String trimRight(final String s){
return trim(s, false);
}
private static String trim(final String s, boolean left){
char[] value = s.toCharArray();
int len = value.length;
int st = 0;
char[] val = value;
if (left){
while ((st < len) && (val[st] <= ' ')) {
st++;
}
}else{
while ((st < len) && (val[len - 1] <= ' ')) {
len--;
}
}
return ((st > 0) || (len < value.length)) ? s.substring(st, len) : s;
}
Bookmarks