Android String Strip strip(String str, String stripChars)

Here you can find the source of strip(String str, String stripChars)

Description

strip

Declaration

public static String strip(String str, String stripChars) 

Method Source Code

//package com.java2s;

public class Main {
    public static String strip(String str, String stripChars) {
        if (isEmpty(str)) {
            return str;
        }//www.ja  va 2  s  .c o m
        str = stripStart(str, stripChars);
        return stripEnd(str, stripChars);
    }

    public static boolean isEmpty(String s) {
        return (s == null || s.length() == 0);
    }

    public static boolean isEmpty(CharSequence cs) {
        return cs == null || cs.length() == 0;
    }

    public static String stripStart(String str, String stripChars) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }
        int start = 0;
        if (stripChars == null) {
            while ((start != strLen)
                    && Character.isWhitespace(str.charAt(start))) {
                start++;
            }
        } else if (stripChars.length() == 0) {
            return str;
        } else {
            while ((start != strLen)
                    && (stripChars.indexOf(str.charAt(start)) != -1)) {
                start++;
            }
        }
        return str.substring(start);
    }

    public static String stripEnd(String str, String stripChars) {
        int end;
        if (str == null || (end = str.length()) == 0) {
            return str;
        }

        if (stripChars == null) {
            while ((end != 0)
                    && Character.isWhitespace(str.charAt(end - 1))) {
                end--;
            }
        } else if (stripChars.length() == 0) {
            return str;
        } else {
            while ((end != 0)
                    && (stripChars.indexOf(str.charAt(end - 1)) != -1)) {
                end--;
            }
        }
        return str.substring(0, end);
    }
}

Related

  1. stripPrefixIgnoreCase(String str, String prefix)
  2. stripPrefix(String str, String prefix)
  3. stripSuffix(String str, String suffix)
  4. stripSuffixIgnoreCase(String str, String suffix)
  5. strip(String str, String stripChars)
  6. stripCharacter(String inputString, char stripCharacter)
  7. stripCharacters(String inputString, String stripCharacters)
  8. stripControlCharacters(Object value)
  9. stripControlCharacters(String value)