Fixed #22. Added support for removeSpaces function

This commit is contained in:
Shekhar Gulati
2016-05-21 19:43:55 +05:30
parent 7a56392896
commit 8ee53f4121
2 changed files with 22 additions and 0 deletions
+11
View File
@@ -733,6 +733,17 @@ public abstract class Strman {
return endsWith(value, suffix, caseSensitive) ? value.substring(0, value.toLowerCase().lastIndexOf(suffix.toLowerCase())) : value;
}
/**
* Remove all spaces and replace for value.
*
* @param value The input String
* @return String without spaces
*/
public static String removeSpaces(final String value) {
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
return value.replaceAll("\\s", "");
}
public static String decode(final String value, final int digits, final int radix) {
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
return Arrays
+11
View File
@@ -560,4 +560,15 @@ public class StrmanTest {
Arrays.stream(fixture).forEach(el -> assertThat(removeRight(el, "BAR", false), equalTo("foo")));
}
@Test
public void removeSpaces_shouldRemoveSpacesInTheString() throws Exception {
final String[] fixture = {
"foo bar",
"foo bar ",
" foo bar",
" foo bar "
};
Arrays.stream(fixture).forEach(el -> assertThat(removeSpaces(el), equalTo("foobar")));
}
}