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

private static boolean isEmpty(String value) {
    return value == null || value.trim().length() == 0;
}

From source file:Main.java

public static String nullsafeTrim(String str) {
    return TextUtils.isEmpty(str) ? str : str.trim();
}

From source file:Main.java

private static boolean isBlank(String value) {
    return value == null || value.trim().length() == 0;
}

From source file:Main.java

/**
 * Strips scheme from the original URL of the offline page. This is meant to be used by UI.
 * @param onlineUrl an online URL to from which the scheme is removed
 * @return onlineUrl without the scheme/*  w w w.j  ava  2 s .c o  m*/
 */
public static String stripSchemeFromOnlineUrl(String onlineUrl) {
    onlineUrl = onlineUrl.trim();
    // Offline pages are only saved for https:// and http:// schemes.
    if (onlineUrl.startsWith("https://")) {
        return onlineUrl.substring(8);
    } else if (onlineUrl.startsWith("http://")) {
        return onlineUrl.substring(7);
    } else {
        return onlineUrl;
    }
}

From source file:Main.java

public static boolean isEmailValid(String email) {
    if (email != null && !email.trim().isEmpty()) {
        Pattern pattern = Pattern.compile("^(.+\\..+)@futurice.com$");
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    } else {/*from w  ww .  j a v  a2  s  . co m*/
        return false;
    }
}

From source file:Main.java

public static boolean isNotEmpty(String str) {
    return (str != null && !str.trim().equals(""));
}

From source file:Main.java

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

From source file:Main.java

private static float getFloatFromString(String s) {
    if (s != null && !s.trim().equals("")) {
        s = s.replaceAll(",", "");

        try {//  w  w  w  .j a  v a 2s . co  m
            if (s.endsWith("%")) {
                return Float.valueOf(s.substring(0, s.length() - 1));
            } else {
                return Float.valueOf(s);
            }
        } catch (NumberFormatException e) {
        }
    }

    return 0;
}

From source file:Main.java

public static boolean isStringNotNullAndNotEmpty(String str) {
    if (str == null || str.trim().length() <= 0) {
        return false;
    }/* www  .ja va2s  .c  o  m*/

    return true;
}

From source file:Main.java

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