Android String Trim betterTrim(String input)

Here you can find the source of betterTrim(String input)

Description

better Trim

Declaration

public static String betterTrim(String input) 

Method Source Code

//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;
    }
}

Related

  1. rightTrimSize(String s)
  2. trim(String s, char c)
  3. trim(String trimStr, String trimChars)
  4. trimEnd(String s, String extraChars)
  5. trimStart(String s, String extraChars)