List of utility methods to do String Whitespace Clean
String | cleanWhitespace(String definition) Helper method to make definition strings more Tab-delimited/Excel friendly if (definition == null) { return "NULL"; return definition.replace("\r", "[CR]").replace("\n", "[LF]").replace("\t", "[TAB]").trim(); |
String | cleanWhitespace(String in) Clean - Remove all white spaces char[] inArray = in.toCharArray(); StringBuffer out = new StringBuffer(inArray.length); boolean lastWasSpace = false; for (int i = 0; i < inArray.length; i++) { char c = inArray[i]; if (Character.isWhitespace(c)) { if (!lastWasSpace) out.append(' '); ... |
String | cleanWhiteSpace(String s, boolean all) clean White Space if (s == null) { return null; s = s.trim(); if (all) { s = s.replaceAll("\\s+", ""); return s; ... |
String | cleanWhitespace(String str) clean Whitespace if (str != null) { return str.trim().replaceAll("\u00a0", ""); return null; |
String | cleanWhitespace(String string) Reduce multiple consecutive whitspaces to a single space (also removing the \n, \t etc.) and also trim the string String reduced = string.replaceAll("\\s+", " "); return reduced.trim(); |
String | cleanWhitespaceAndIndentation(String s, String indent) clean Whitespace And Indentation String res = s.replaceAll("[\r\n]", "\n") .replaceAll("\n\\s*", "\n") .replaceAll("\\s*\n", "\n") .replaceAll("[\r\n]", "\n" + indent) .replaceAll("\n\\s*\n", "\n") .replaceAll("}\n", "}\n\n"); if (indent.length() >= 2) { res = res.replaceAll("\n\\s*}$", "\n" + indent.substring(2) + "}"); ... |
String | cleanWhitespaces(String string) Replace whitespace characters with space character. if (string != null) { char[] cc = string.toCharArray(); for (int ci = cc.length - 1; ci > 0; ci--) { if (Character.isWhitespace(cc[ci])) { cc[ci] = ' '; return new String(cc); ... |