Example usage for java.lang String contains

List of usage examples for java.lang String contains

Introduction

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

Prototype

public boolean contains(CharSequence s) 

Source Link

Document

Returns true if and only if this string contains the specified sequence of char values.

Usage

From source file:Main.java

public static String escapeXMLField(String field) {
    if (field.contains("&")) {
        int index = 0;
        do {/*from  w  ww .  java  2  s  .  c  om*/
            index = field.indexOf("&", index);
            if (index != -1 && !field.substring(index).startsWith("&"))
                field = field.substring(0, index) + "&" + field.substring(index + 1, field.length());
            if (index != -1)
                index++;
        } while (index != -1);
    }
    field = field.replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'",
            "&apos;");
    return field;
}

From source file:Main.java

public static String findValueInUrl(String url, String key) {
    String[] params = url.split("&");

    String value = "";

    for (String p : params) {
        if (p.contains(key)) {
            try {
                value = URLDecoder.decode(p.split("=")[1], "utf-8");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();/*w  ww. j a  va 2 s .c om*/
            }
        }
    }

    return value;
}

From source file:Main.java

public static int getColorFromHex(String color) {
    if (color.contains("0x"))
        color = color.replace("0x", "");
    // if (color.contains("#"))
    // color = color.replace("#", "");
    // return Integer.parseInt(color, 16) + 0xFF000000;
    if (!color.contains("#")) {
        StringBuffer colorBuffer = new StringBuffer("#");
        colorBuffer.append(color);/*from w  w  w .ja  v a 2 s  .c  om*/
        return Color.parseColor(colorBuffer.toString());
    }
    //
    return Color.parseColor(color);
    // StringBuffer colorBuffer = new StringBuffer("0xff");
    // colorBuffer.append(color);
    // int value = Integer.parseInt(colorBuffer.toString(), 16);
    // int red = ((value >> 24) & 0xFF) / 255;
    // int green = ((value >> 16) & 0xFF) / 255;
    // int blue = ((value >> 8) & 0xFF) / 255;
    // int alpha = ((value >> 0) & 0xFF) / 255;
    // Color.parseColor(colorString);
    // return Color.argb(alpha, red, green, blue);
}

From source file:Main.java

public static String[] splitString(String str, String del) {
    String[] res;/*from   w ww .j a  va  2 s  .c  o  m*/
    if (str.contains(del)) {
        res = str.split(del);
    } else {
        res = new String[] { str };
    }
    return res;
}

From source file:Main.java

public static String getsmsidfromID(String id) {

    String val = "";

    if (id.contains("motor")) {

        int num = Integer.parseInt(id.substring(5, 6));
        val = "M" + num;
    }//from  w w w.  j a v a 2s .  c  o  m

    return val;

}

From source file:Main.java

public static boolean isNicknameValid(String nickname) {
    String trimmed = nickname.trim();
    return !(trimmed.isEmpty() || trimmed.contains(" "));
}

From source file:Main.java

public static void installApk(Context context, String fileName) {
    if (fileName != null && fileName.contains(".apk")) {
        //         File f = new File(fileName);
        //         if(f.exists()){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setDataAndType(Uri.parse("file://" + fileName), "application/vnd.android.package-archive");
        context.startActivity(intent);//from w ww  . j a  v a 2  s . c om
        //         }
    }
}

From source file:Main.java

private static String removeProtocol(String domain) {
    if (domain.contains("https://")) {
        return domain.substring(8);
    }/* w ww. ja  v  a2  s.  co m*/
    if (domain.startsWith("http://")) {
        return domain.substring(7);
    } else
        return domain;
}

From source file:Main.java

public static boolean isInvalidPictureFile(String mimeType) {
    String lowerCaseFilepath = mimeType.toLowerCase();
    return (lowerCaseFilepath.contains("jpg") || lowerCaseFilepath.contains("jpeg")
            || lowerCaseFilepath.toLowerCase().contains("png")
            || lowerCaseFilepath.toLowerCase().contains("bmp")
            || lowerCaseFilepath.toLowerCase().contains("gif"));
}

From source file:Main.java

/**
 * @brief      Check whether url is a taobao like one
 * /*from   ww  w  .ja v a 2 s  . c o  m*/
 * @param      url   [IN]  url value
 * 
 * @return     Return true if url is a taobao like one
 */
public static boolean isTaoBaoLikeUrl(String url) {
    if (url != null) {
        if (url.contains(URL_MAIN_TAOBAO_WORD)) {
            return true;
        }
    }
    return false;
}