Returns true if string s is empty or whitespace characters only.
(String s)
| 207 | |
| 208 | /** Returns true if string s is empty or whitespace characters only. */ |
| 209 | public static boolean isWhitespace(String s) { |
| 210 | // Is s empty? |
| 211 | if (isEmpty(s)) return true; |
| 212 | |
| 213 | // Search through string's characters one by one |
| 214 | // until we find a non-whitespace character. |
| 215 | // When we do, return false; if we don't, return true. |
| 216 | for (int i = 0; i < s.length(); i++) { |
| 217 | // Check that current character isn't whitespace. |
| 218 | char c = s.charAt(i); |
| 219 | |
| 220 | if (whitespace.indexOf(c) == -1) return false; |
| 221 | } |
| 222 | // All characters are whitespace. |
| 223 | return true; |
| 224 | } |
| 225 | |
| 226 | /** Removes all characters which appear in string bag from string s. */ |
| 227 | public static String stripCharsInBag(String s, String bag) { |