Example usage for java.lang String length

List of usage examples for java.lang String length

Introduction

In this page you can find the example usage for java.lang String length.

Prototype

public int length() 

Source Link

Document

Returns the length of this string.

Usage

From source file:Main.java

static boolean isNullOrEmpty(String str) {
    if (str == null || str.length() == 0) {
        return true;
    }/*from  ww w .j a  v  a 2  s .c o  m*/
    return false;
}

From source file:Main.java

private static boolean isShortColorCode(String colorString) {
    return colorString.length() == 4 && colorString.startsWith("#") && isHexadecimalColor(colorString);
}

From source file:Main.java

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

From source file:Main.java

public static String Splitme(String str) {
    if (str != null && str.length() > 0 && str.charAt(str.length() - 1) == ',') {
        str = str.substring(0, str.length() - 1);
    }/*  ww w.j  av  a 2s .  co  m*/
    return str;
}

From source file:Main.java

public static byte[] toBytesFromUnicode(String s) {
    int limit = s.length() * 2;
    byte[] result = new byte[limit];
    char c;//from   w  ww  .  j a va2  s  .c om
    for (int i = 0; i < limit; i++) {
        c = s.charAt(i >>> 1);
        result[i] = (byte) (((i & 1) == 0) ? c >>> 8 : c);
    }
    return result;
}

From source file:Main.java

public static String capitalize(String s) {
    if (s.length() == 0)
        return s;
    return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
}

From source file:Main.java

private static byte[] parseHexStr2Byte(String hexStr) {
    if (hexStr.length() < 1)
        return null;
    byte[] result = new byte[hexStr.length() / 2];
    for (int i = 0; i < hexStr.length() / 2; i++) {
        int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
        int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
        result[i] = (byte) (high * 16 + low);
    }/*w w  w. jav  a 2 s  . co  m*/
    return result;
}

From source file:Main.java

/**
 * Extracts a GTIN from a GS1-128 (Code 128) formatted bar code.
 *
 * @param code/*from   ww w . j av  a  2 s . c  o m*/
 *         the raw bar code value
 * @return the extracted GTIN or null if none found
 */
public static String extractFromCode128(String code) {
    if (code.length() < 16) {
        return null;
    }
    if (code.startsWith("01") || code.startsWith("02")) {
        return code.substring(2, 16);
    }
    return null;
}

From source file:Main.java

public static String replaceStringSpaceToUnderScore(String str) {
    if (str == null || str.length() == 0) {
        return "";
    }/*from   w w w.  j  a  v  a2  s .co  m*/
    return str.replace(" ", "_");
}

From source file:Main.java

/**
 * Extracts a GTIN from a GS1 DataMatrix formatted bar code.
 *
 * @param code//from   w  w  w  . j av  a  2  s.c o m
 *         the raw bar code value
 * @return the extracted GTIN or null if none found
 */
public static String extractFromDataMatrix(String code) {
    if (code.length() < 16) {
        return null;
    }
    if (code.startsWith("01")) {
        return code.substring(2, 16);
    }
    return null;
}