Example usage for java.lang String trim

List of usage examples for java.lang String trim

Introduction

In this page you can find the example usage for java.lang String trim.

Prototype

public String trim() 

Source Link

Document

Returns a string whose value is this string, with all leading and trailing space removed, where space is defined as any character whose codepoint is less than or equal to 'U+0020' (the space character).

Usage

From source file:Main.java

public static boolean checkMinLength(String value, int min) {
    String tmp = value.trim();
    if (tmp.length() >= min) {
        return true;
    } else {//from   w  w w.  j  a  v a2s . c o m
        return false;
    }
}

From source file:Main.java

public static String trim(String str) {
    return str == null ? "" : str.trim();
}

From source file:Main.java

public static boolean isNullOrEmpty(String str) {
    if (str == null || str.trim().equals("")) {
        return true;
    }// ww w  .j  av  a  2s.com
    return false;
}

From source file:Main.java

/**
 * Check for a given String if it is Empty which means it is either null or has zero length,
 * when trimmed./*from   www  . j  a v  a 2  s . co  m*/
 *
 * @param string
 */
public static boolean isEmpty(String string) {
    return string == null || string.trim().length() == 0;
}

From source file:Main.java

public static synchronized String trim(String str) {
    String temp = str.trim();
    int index = 0;
    for (int i = 0; i < temp.length(); i++) {
        char ch = temp.charAt(i);
        if (ch == '.' || ch == '/' || ch == '\\') {
            index++;/*from w ww .  j a  v  a  2s .c  o  m*/
        } else
            break;
    }

    return temp.substring(index, temp.length());
}

From source file:Main.java

public static String wrap(String in, final int len) {
    in = in.trim();
    if (in.length() < len)
        return in;
    if (in.substring(0, len).contains("\n"))
        return in.substring(0, in.indexOf("\n")).trim() + "\n\n"
                + wrap(in.substring(in.indexOf("\n") + 1), len);
    int place = Math.max(Math.max(in.lastIndexOf(" ", len), in.lastIndexOf("\t", len)),
            in.lastIndexOf("-", len));
    return in.substring(0, place).trim() + "\n" + wrap(in.substring(place), len);
}

From source file:Main.java

public static String cleanupTextString(String contents) {
    if (contents == null || contents.trim().equals(""))
        return null;
    else//from   w w w.  ja  v  a  2s  .c  o  m
        return contents.trim();
}

From source file:Main.java

/**
 * Gives the first alphabet of the string if its not empty or null.
 * /* ww w.  jav  a2s  .c o  m*/
 * @param name
 * @return
 */
public static String getFallbackTextInitials(String name) {
    if (name != null && !name.trim().isEmpty()) {
        return name.substring(0, 1);
    }
    return null;
}

From source file:Main.java

/**
 * /*from   w  w  w . ja  v a2  s.co m*/
 * @param xml
 * @return linearized
 */
public static String linarizeXml(String xml) {

    return (xml != null) ? xml.trim().replaceAll(XML_LINEARIZATION_REGEX, XML_LINEARIZATION_REPLACEMENT) : null;
}

From source file:Main.java

public static Set<Integer> getNumsFromStr(String text) {
    text = null == text ? "" : text;
    String[] ary = text.replaceAll("[^\\d]", " ").split("\\s+");
    Set<Integer> set = new TreeSet<Integer>();
    for (String num : ary) {
        if (!num.trim().equals("")) {
            set.add(Integer.valueOf(num.trim()));
        }//from   w w  w.  ja v a 2s . com
    }
    return set;
}