분명 비어있는 데 trim 을 했을 경우 안없어지는 경우가 발생할 수 있다. 

그럴경우 아래 함수를 실행해보자.

public static String trimAdvanced(String value) {

Objects.requireNonNull(value);

int strLength = value.length();
int len = value.length();
int st = 0;
char[] val = value.toCharArray();

if (strLength == 0) {
return "";
}

while ((st < len) && (val[st] <= ' ') || (val[st] == '\u00A0')) {
st++;
if (st == strLength) {
break;
}
}
while ((st < len) && (val[len - 1] <= ' ') || (val[len - 1] == '\u00A0')) {
len--;
if (len == 0) {
break;
}
}


return (st > len) ? "" : ((st > 0) || (len < strLength)) ? value.substring(st, len) : value;
}


'링크모음 > java' 카테고리의 다른 글

java9 빠르게 핵심만  (0) 2017.11.07
대표적인 소프트웨어 아키텍쳐 10가지  (0) 2017.09.15
DTO와 VO 차이점..  (0) 2017.08.09

+ Recent posts