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

/**
 * Normalize a text string as per XPath normalize() function.
 * // w  w w. j  a  v a2  s  .c o m
 * @param s
 *            The string to normalize.
 * @return The normalized text as character array.
 */
public static char[] normalizeText(String s) {
    char[] ch = s.trim().toCharArray();
    if (ch.length == 0) {
        return ch;
    }
    return normalizeTrimmedText(ch);
}

From source file:Main.java

public static JSONObject newJSONObject(String val) {
    try {/* www. ja v  a 2 s .  c  om*/
        return new JSONObject(val.trim());
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

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

From source file:Main.java

public static Set<String> parseSeparetedStringSet(String inputString, String delim) {
    Set<String> ret = new TreeSet<String>();

    String[] data = inputString.split(delim);

    for (String d : data) {
        ret.add(d.trim());
    }/*w ww.  j a v a2s .c  o  m*/

    return ret;
}

From source file:Main.java

/**
 * Function to validate a string and check if the string is valid or not.
 * @param string string that need to be validated.
 * @return true if the string is valid and false if the string is invalid.
 */// w ww  .j  av a 2s  .  c om
public static boolean isValidString(String string) {
    return string != null && !string.trim().equalsIgnoreCase("null") && !string.trim().equalsIgnoreCase("");
}

From source file:Main.java

public static float getRating(String rate) {
    if (rate != null) {
        if (rate.trim().length() == 2) {
            return Float.valueOf(rate) / 10;
        } else {//from w  w  w .j a  v a 2 s .  c om
            return Float.valueOf(rate);
        }
    }
    return 0;
}

From source file:Main.java

public static void deleteFile(String imageLocation) {
    if (imageLocation != null && imageLocation.trim().length() > 5) {
        File file = new File(imageLocation);
        if (file.exists()) {
            boolean fi = file.delete();
        }/*from ww w .  j a va  2 s.c  o m*/
    }
}

From source file:Main.java

public static boolean isName(String s) {
    if (null == s || "".equals(s.trim()))
        return false;
    for (int i = 0; i < s.length(); i++) {
        if (!isChinese(s.charAt(i)) && !isEnglish(s.charAt(i)) && s.charAt(i) != ' '
                && !".".equals(s.charAt(i)))
            return false;
    }/*from w w  w. j  a v  a 2  s .  co  m*/
    return true;
}

From source file:Main.java

public static boolean checkUrlNotNull(String url) {
    return url != null && !TextUtils.isEmpty(url) && url.trim().length() != 0;
}

From source file:Main.java

public static void showSimpleAlert(Context context, String title, String message) {
    if (null == title || title.trim().length() == 0)
        title = "Oops";
    if (null == message || message.trim().length() == 0)
        message = "Invalid operation.";
    new AlertDialog.Builder(context).setTitle(title).setMessage(message).setNeutralButton("Go Back", null)
            .show();//from  w  w w.  j a  va2s.  c  om
}