The list of methods to do String Whitespace Normalize are organized into topic(s).
String
normaliseWhitespace(String string) normalise Whitespace
StringBuilder sb = new StringBuilder(string.length());
boolean lastWasWhite = false;
boolean modified = false;
int l = string.length();
for (int i = 0; i < l; i++) {
int c = string.codePointAt(i);
if (Character.isWhitespace(c)) {
if (lastWasWhite) {
...
String
normaliseWhitespace(String string) Normalise the whitespace within this string; multiple spaces collapse to a single, and all whitespace characters (e.g.
StringBuilder sb = new StringBuilder(string.length());
appendNormalisedWhitespace(sb, string, false);
return sb.toString();
String
normalizeIndentationFromWhitespace(String str, int tabSize, boolean insertSpaces) normalize Indentation From Whitespace
int spacesCnt = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '\t') {
spacesCnt += tabSize;
} else {
spacesCnt++;
StringBuilder result = new StringBuilder();
if (!insertSpaces) {
long tabsCnt = Math.round(Math.floor(spacesCnt / tabSize));
spacesCnt = spacesCnt % tabSize;
for (int i = 0; i < tabsCnt; i++) {
result.append('\t');
for (int i = 0; i < spacesCnt; i++) {
result.append(' ');
return result.toString();
String
normalizeWhitespace(String dirtyString) Trim string and convert all multi whitespace regions to a single space.
if (dirtyString == null) {
return null;
if (dirtyString.length() < 1) {
return dirtyString;
StringBuffer buff = new StringBuffer();
int dsl = dirtyString.length();
...
String
normalizeWhiteSpace(String input) normalize White Space
if (input == null) {
return null;
StringBuffer result = new StringBuffer();
boolean atStart = true;
boolean whitespaceToInsert = false;
for (int i = 0; i < input.length(); i++) {
char next = input.charAt(i);
...
String
normalizeWhitespace(String orig) Replace any string of whitespace characters with a single space, and remove whitespace from the beginning and end of the string.
return orig.replaceAll("\\s+", " ").trim();
String
normalizeWhitespace(String s) Removes all leading and trailing whitespace from a string, and replaces all internal whitespace with a single space character.
String normalized = "";
if (s != null) {
s = s.trim();
boolean prevIsWhitespace = false;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
boolean thisIsWhitespace = (c <= 0x20);
if (!(thisIsWhitespace && prevIsWhitespace)) {
...