Here you can find the source of betterTrim(String input)
public static String betterTrim(String input)
//package com.java2s; public class Main { public static String betterTrim(String input) { input = input.trim();/* www .j a v a 2 s .c o m*/ if (input.length() == 0) { return input; } boolean didChange; do { String oldInput = input; char firstChar = input.charAt(0); if (Character.isWhitespace(firstChar) || firstChar == '\u00A0' || firstChar == '\u2007' || firstChar == '\u202F') { input = input.substring(1); } if (input.length() > 0) { char lastChar = input.charAt(input.length() - 1); if (Character.isWhitespace(lastChar) || lastChar == '\u00A0' || lastChar == '\u2007' || lastChar == '\u202F') { input = input.substring(0, input.length() - 1); } } didChange = false; if (!input.equals(oldInput)) { didChange = true; } } while (didChange && input.length() > 0); return input; } }