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 String getBubleText(String bubleNum) {
    if (bubleNum != null) {
        if (bubleNum.trim().length() >= 3) {
            bubleNum = "99+";
        }/*  ww  w.  j av a 2 s.co  m*/
    }
    return bubleNum;
}

From source file:Main.java

public static String getNamedTextElemXml(String tagName, String value) {
    if (value == null || value.trim().length() < 1) {
        return "<" + tagName + "/>";
    }//from  w  ww  . jav  a2 s. co  m
    return "<" + tagName + "><![CDATA[" + value + "]]></" + tagName + ">";
}

From source file:Main.java

public static boolean isAvailable(String temp) {
    boolean b = true;
    if (temp == null || temp.trim().equals("")) {
        b = false;//from w w  w .j a v a  2  s  .c  o m
    }
    return b;
}

From source file:Main.java

public static String getCurrentTimeString(String format) {
    if (format == null || format.trim().equals("")) {
        sdf.applyPattern(FORMAT_DATE_TIME);
    } else {//  w w  w .  j a  v a 2  s. c  om
        sdf.applyPattern(format);
    }
    return sdf.format(new Date());
}

From source file:Main.java

/**
 * Convert integer wraped in string to int safely.
 *///from   w  ww. j av a 2 s .co m
public static int toIntSafely(String text) {
    int result = -1;

    text = text.trim();
    try {
        result = Integer.parseInt(text);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    return result;
}

From source file:Main.java

/**
 * <p>Removes control characters (char &lt;= 32) from both
 * ends of this String, handling {@code null} by returning
 * {@code null}.</p>/*from   ww  w  . j  a v  a  2 s . c o m*/
 * <p>
 * <p>The String is trimmed using {@link String#trim()}.
 * Trim removes start and end characters &lt;= 32.
 * <p>
 * <p>To trim your choice of characters, use the
 * <p>
 * <pre>
 * StringUtils.trim(null)          = null
 * StringUtils.trim("")            = ""
 * StringUtils.trim("     ")       = ""
 * StringUtils.trim("abc")         = "abc"
 * StringUtils.trim("    abc    ") = "abc"
 * </pre>
 *
 * @param str the String to be trimmed, may be null
 * @return the trimmed string, {@code null} if null String input
 */
public static String trim(final String str) {
    return str == null ? null : str.trim();
}

From source file:Main.java

/**
 * Toglie placeholder e spazi all'inizio e alla fine.
 *
 * @param s valore da normalizzare/*w  w  w. ja  v a 2s .c  o m*/
 * @return valore normalizzato
 */
public static String normalize(String s) {
    String s1 = s.replaceAll("_*$", "");
    return s1.trim();
}

From source file:Main.java

public static boolean isNotBlank(String str) {
    return !TextUtils.isEmpty(str) && !TextUtils.isEmpty(str.trim());
}

From source file:Main.java

/**
 * 01061234567 010-61234567 13611111111 400-400-4000
 *
 * @param phoneNumStr phoneNum/* ww  w.java 2  s.c  o m*/
 * @return boolean
 */
public static boolean isPhoneNumber(String phoneNumStr) {
    if (phoneNumStr == null || phoneNumStr.trim().length() == 0) {
        return false;
    }
    Matcher matcherTelNo = patternTelNo.matcher(phoneNumStr);
    return matcherTelNo.find();
}

From source file:cn.guoyukun.spring.utils.ImagesUtils.java

/**
 * ?//from  w  w  w .j av  a  2s.  co m
 *
 * @param filename
 * @return
 */
public static boolean isImage(String filename) {
    if (filename == null || filename.trim().length() == 0)
        return false;
    return ArrayUtils.contains(IMAGES_SUFFIXES, FilenameUtils.getExtension(filename).toLowerCase());
}