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 containsAnyData(String[] row) {
    if (row == null || row.length == 0) {
        return false;
    }/*from   ww w.j a v a2s.  co m*/
    for (String value : row) {
        if (value != null && value.trim().length() > 0) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static String ntrim(String str) {
    if (str == null)
        return null;
    str = str.trim();
    if (str.length() == 0)
        return null;
    return str;//from w w  w .  j  a  va  2s .  c o  m
}

From source file:Main.java

private static String makeEmailHerf(String content) {
    if (content.trim().length() == 0) {
        return content;
    }/*from   w ww.ja v  a2s . c  o  m*/
    StringBuffer emailStringBuffer = new StringBuffer();

    Matcher matcherEmail = patternEmail.matcher(content);
    while (matcherEmail.find()) {

        String email = matcherEmail.group();
        //            System.out.println("email:" + email);
        String emailToHref = "<a href=\"" + MailTo.MAILTO_SCHEME + email + "\">" + email + "</a>";
        matcherEmail.appendReplacement(emailStringBuffer, emailToHref);

    }
    matcherEmail.appendTail(emailStringBuffer);
    return emailStringBuffer.toString();
}

From source file:Main.java

private static String makeTelNoHerf(String telContent) {
    if (telContent.trim().length() == 0) {
        return telContent;
    }//from ww  w.j  a v  a2s  . c o m
    StringBuffer telNoStringBuffer = new StringBuffer();

    Matcher matcherTelNo = patternTelNo.matcher(telContent);
    while (matcherTelNo.find()) {

        String telNo = matcherTelNo.group();
        String telNoToHerf = "<a href=\"" + ProtocolKey_ACTION_DIAL + telNo + "\">" + telNo + "</a>";
        matcherTelNo.appendReplacement(telNoStringBuffer, telNoToHerf);

    }
    matcherTelNo.appendTail(telNoStringBuffer);
    return telNoStringBuffer.toString();
}

From source file:Main.java

public static String truncateAndTrailOffText(String text, int limit) {
    String trimmed = text.trim();
    int dotsLength = F_DOTS.length();
    int trimmedLength = trimmed.length();
    int limitWithDots = limit - dotsLength;

    if (limit >= trimmedLength) {
        return trimmed;
    }//  w w w. j  a  va2 s .  com
    // limit <= trimmedLength
    if (limit <= dotsLength) {
        return ""; //$NON-NLS-1$
    }
    // dotsLength < limit < trimmedLength
    return trimmed.substring(0, limitWithDots) + F_DOTS;
}

From source file:Main.java

public static String mergeLines(String linesText) {
    String ret_value = "";
    String[] lines = linesText.split("\n");

    if (lines != null) {
        for (String line : lines) {
            ret_value = ret_value + " " + line.trim();
        }//  www  .j  a v a2s. c  o  m
    } else {
        ret_value = linesText.replaceAll("\t", "").replaceAll("\n", " ");
    }
    return ret_value.trim();
}

From source file:Main.java

public static boolean isNullOrEmpty(final String str) {
    if (str == null)
        return true;
    if (str.trim().equals(""))
        return true;
    return false;
}

From source file:Main.java

public static boolean isNullOrEmpty(String str) {

    return str == null || str.length() == 0 || str.trim().length() == 0;
}

From source file:Main.java

public static boolean isEmpty(String str) {
    return str == null ? true : ("".equals(str.trim()) ? true : false);
}

From source file:Main.java

public static String convertEntities(String text) {
    if ("".equals(text.trim())) {
        return "";
    }/* ww  w. j  av a2s.  co m*/
    if (text.indexOf(AMP_CHARACTER) != -1) {
        text = text.replaceAll(AMP_STRING, AMP_ENTITY);
    }
    if (text.indexOf(APOS_CHARACTER) != -1) {
        text = text.replaceAll(APOS_STRING, APOS_ENTITY);
    }
    if (text.indexOf(LT_CHARACTER) != -1) {
        text = text.replaceAll(LT_STRING, LT_ENTITY);
    }
    if (text.indexOf(GT_CHARACTER) != -1) {
        text = text.replaceAll(GT_STRING, GT_ENTITY);
    }
    if (text.indexOf(QUOTE_CHARACTER) != -1) {
        text = text.replaceAll(QUOTE_STRING, QUOTE_ENTITY);
    }
    return text;
}