Example usage for java.lang String indexOf

List of usage examples for java.lang String indexOf

Introduction

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

Prototype

public int indexOf(String str) 

Source Link

Document

Returns the index within this string of the first occurrence of the specified substring.

Usage

From source file:Main.java

public static int getTopicFromFileName(String fileName) {
    int startTopicIndex = fileName.indexOf("topic_");
    int lastTopicIndex = fileName.lastIndexOf("_topic");
    if (startTopicIndex >= 0 && lastTopicIndex >= 0) {
        try {//  w w  w  . j  a  v a 2  s.c  o m
            return Integer.parseInt(fileName.substring(startTopicIndex + 6, lastTopicIndex));
        } catch (Exception e) {
            return -2;
        }
    }
    return -1;
}

From source file:Main.java

public static HashMap<String, String> paserParams(String url) {
    String params = url.substring(url.indexOf("?") + 1);
    String[] arr = params.split("&");
    HashMap<String, String> maps = new HashMap<String, String>();
    for (String s : arr) {
        maps.put(s.substring(0, s.indexOf("=")), s.substring(s.indexOf("=") + 1));
    }//w  w  w  . ja  va2s . c om
    return maps;
}

From source file:Main.java

public static int extractSdkLevel(String content) {
    return Integer.parseInt(content.substring(content.indexOf("API ") + 4, content.indexOf(":")));
}

From source file:Main.java

/**
 * Extracts unique musicID from the mediaID. mediaID is, by this sample's convention, a
 * concatenation of category (eg "by_genre"), categoryValue (eg "Classical") and unique
 * musicID. This is necessary so we know where the user selected the music from, when the music
 * exists in more than one music list, and thus we are able to correctly build the playing queue.
 *
 * @param mediaID that contains the musicID
 * @return musicID/*from  www .j a v a2 s.  co  m*/
 */
public static String extractMusicIDFromMediaID(@NonNull String mediaID) {
    int pos = mediaID.indexOf(LEAF_SEPARATOR);
    if (pos >= 0) {
        return mediaID.substring(pos + 1);
    }
    return null;
}

From source file:Main.java

/**
 * Replace greek character entity names with entity names that work in HTML.
 * @param value input string/*from w  w w . java 2  s . com*/
 * @return string with replacements
 */
public static String fixEntityNames(String value) {
    String retVal = value;

    if (retVal.indexOf('&') != -1) {
        for (Map.Entry<String, String> entry : replacements.entrySet()) {
            String orig = entry.getKey();
            String replacement = entry.getValue();
            retVal = retVal.replaceAll("&" + orig + ";", "&" + replacement + ";");
            if (retVal.indexOf('&') == -1) {
                break;
            }
        }
    }

    return retVal;
}

From source file:Main.java

public static boolean isWo2bHost(String url) {
    String host = getHost(url);
    if (host != null && host.indexOf("wo2b.com") != -1)
    // if (host != null && host.indexOf("wo2b") != -1)
    {/* ww  w.j a  v a  2s .c om*/
        return true;
    }

    return false;
}

From source file:Main.java

/**
 * /*w ww . j  a  v  a2s.co m*/
 * @param rawNumber
 * @return username - null if the number is invalid
 */
public static String generateUsernameFromPhoneNumber(String rawNumber) {
    int indexDoubleZero = rawNumber.indexOf("00");
    String username = "";
    if (indexDoubleZero == 0) {
        username = "p" + rawNumber.substring(2);
    } else if (rawNumber.charAt(0) == '+') {
        username = "p" + rawNumber.substring(1);
    } else if (rawNumber.charAt(0) == '0') {
        username = "p" + getCountryCode() + rawNumber.substring(1);
    } else {
        return null;
    }
    return username;
}

From source file:Main.java

private static String parseEndXMLCData(String strValue) {
    int pos = strValue.indexOf("]]>");
    StringBuffer sb = new StringBuffer();
    if (pos > -1) {
        sb.append("<![CDATA[");
        sb.append(strValue.substring(0, pos + 1));
        sb.append("]]>");
        sb.append(parseEndXMLCData(strValue.substring(pos + 1)));
    } else {// w  w w.  ja va  2s  .c  o m
        sb.append("<![CDATA[");
        sb.append(strValue);
        sb.append("]]>");
    }
    return sb.toString();
}

From source file:Main.java

public static String getSubString(String str, String string, int index) {
    return str.substring(str.indexOf(string) + index);
}

From source file:Main.java

/**
 * Gets the tag value without namespace.
 * //from w w w.  j  av  a2 s .c o m
 * @param n
 *            the n
 * @return the tag value without namespace
 */
public static String getTagValueWithoutNamespace(Node n) {
    if (n != null) {
        String tag = n.getNodeName();
        return tag.substring(tag.indexOf(":") + 1, tag.length());
    }
    return null;
}