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 isEmpty(String str) {
    return str == null || str.trim().length() == 0 || str.trim().equals("null");
}

From source file:Main.java

/**
 * Replaces common newline characters like \n, \r, \r\n to the HTML line
 * break tag <br>.//w  w w . j  a v a2s. co m
 *
 * @param text the text to substitute.
 * @return the substituted text.
 */
public static String htmlNewline(String text) {
    if (text == null || text.trim().isEmpty()) {
        return null;
    }

    return text.replaceAll("(\n|\r|\r\n)", "<br>");
}

From source file:Main.java

public static boolean isEmpty(String str) {
    return str == null || str.trim().length() == 0 || "".equals(str);
}

From source file:Main.java

/**
 * Returns null if the given string is not null and contains no characters,
 * the string itself otherwise.//from  w  ww  .j a va 2s  .  c o  m
 *
 * @param string the string.
 * @return null if the given string is not null and contains no characters,
 * the string itself otherwise.
 */
public static String nullIfEmpty(String string) {
    return string != null && string.trim().length() == 0 ? null : string;
}

From source file:Main.java

public static boolean isEmpty(String str) {
    if (str == null || "".equals(str.trim())) {
        return true;
    }/* w  w w.java  2  s . c om*/
    return false;
}

From source file:Main.java

public static String textIsNull(String text) {
    if (text == null || "".equals(text.trim()) || "null".equalsIgnoreCase(text.trim())) {
        return "";
    }/*from w  w  w  .ja  va2  s.  c  o m*/
    return text;
}

From source file:Main.java

/**
 * Calculates a key name from a file name.
 * @param friendlyName/*w  w w  . jav a2 s  . co  m*/
 * @return a file system friendly name for this password key
 */
public static String calculateKey(String friendlyName) {
    friendlyName = friendlyName.trim().toLowerCase();
    friendlyName = friendlyName.replaceAll("\\Q \\E", "-");
    friendlyName = friendlyName.replaceAll("[!@#$%^&*()+\"]", "_");
    return friendlyName;
}

From source file:Main.java

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

From source file:Main.java

public static boolean isPhone(String phoneNum) {
    if (phoneNum == null || phoneNum.trim().length() == 0)
        return false;
    return phone.matcher(phoneNum).matches();
}

From source file:Main.java

public static boolean isNullOrEmptyWithTrim(String source) {
    return null == source || "".equals(source.trim());
}