Browse Source

Merge pull request #562 from hengyunabc/master

* pull562:
  Improve StringUtils#trimAllWhitespace
pull/563/head
Stephane Nicoll 11 years ago
parent
commit
c2356e57c8
  1. 14
      spring-core/src/main/java/org/springframework/util/StringUtils.java

14
spring-core/src/main/java/org/springframework/util/StringUtils.java

@ -216,14 +216,12 @@ public abstract class StringUtils { @@ -216,14 +216,12 @@ public abstract class StringUtils {
if (!hasLength(str)) {
return str;
}
StringBuilder sb = new StringBuilder(str);
int index = 0;
while (sb.length() > index) {
if (Character.isWhitespace(sb.charAt(index))) {
sb.deleteCharAt(index);
}
else {
index++;
int len = str.length();
StringBuilder sb = new StringBuilder(str.length());
for (int i = 0; i < len; i++) {
char c = str.charAt(i);
if (!Character.isWhitespace(c)) {
sb.append(c);
}
}
return sb.toString();

Loading…
Cancel
Save