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

static void destroySelfProcess(ActivityManager activityManger) {
    List<ActivityManager.RunningAppProcessInfo> appProcessList = activityManger.getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo appProcessInfo : appProcessList) {
        int pid = appProcessInfo.pid;
        String processName = appProcessInfo.processName;
        if (-1 != processName.indexOf("com.wxlh.sptas")) {
            android.os.Process.killProcess(pid);
        }//from  ww w. jav a 2 s. c  om
    }
}

From source file:Main.java

/**
 * Make a list of all URL's that can be found in a string.
 * @param aSource  A string, possibly containing URL's.
 * @return A List of URL's that could be scraped from the string.
 *//*w ww.j a  v a2  s.c o  m*/
public static java.util.List<String> extractUrl(String aSource) {
    final String lPrefix = "http://";
    final java.util.List<String> lResult = new ArrayList<String>();
    String lTodo = aSource;
    int lUrlPos = lTodo.indexOf(lPrefix);
    while (lUrlPos >= 0) {
        lUrlPos += lPrefix.length();
        StringBuilder lUrlBuf = new StringBuilder();
        while ((lUrlPos < lTodo.length()) && lTodo.charAt(lUrlPos) != '\n'
                && !Character.isSpaceChar(lTodo.charAt(lUrlPos)))
            lUrlBuf.append(lTodo.charAt(lUrlPos++));
        lResult.add(lUrlBuf.toString());

        if (lUrlPos < lTodo.length())
            lTodo = lTodo.substring(lUrlPos);
        else
            lTodo = "";
        lUrlPos = lTodo.indexOf(lPrefix);
    }
    return lResult;
}

From source file:Main.java

/**
 * From http://stackoverflow.com/questions/13592236/parse-a-uri-string-into-name-value-collection
 *//*  ww  w .  j a  v a2 s . c  o m*/
public static Map<String, List<String>> splitQuery(String urlQuery) throws UnsupportedEncodingException {
    final Map<String, List<String>> query_pairs = new LinkedHashMap<>();
    final String[] pairs = urlQuery.split("&");
    for (String pair : pairs) {
        final int idx = pair.indexOf("=");
        final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair;
        if (!query_pairs.containsKey(key)) {
            query_pairs.put(key, new LinkedList<String>());
        }
        final String value = idx > 0 && pair.length() > idx + 1
                ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8")
                : null;
        query_pairs.get(key).add(value);
    }
    return query_pairs;
}

From source file:Main.java

public static byte[] getBytesFromDataURI(String dataURI) {
    final String base64 = dataURI.substring(dataURI.indexOf(',') + 1);
    return getBytesFromBase64(base64);
}

From source file:Main.java

/**
 * Method to find if the given key is part of any of the array values
 * <p>//  ww w  . ja  v a  2  s . c  om
 * e.g. if array contains <i>"abc"</i> and given key is <i>"abcdef"</i>; true is returned
 * </p>
 * 
 * @param array
 *            Array to be scanned
 * @param key
 *            key
 * @return boolean true if partial key is found
 */
public static boolean arrayContainsPartKey(String[] array, String key) {
    for (String string : array) {
        if (key.indexOf(string) != -1) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static boolean isOnClasspath(String fullyQualifiedName, IJavaProject project) {
    if (fullyQualifiedName.indexOf('$') != -1)
        fullyQualifiedName = fullyQualifiedName.replace('$', '.');
    try {/*from w  ww .  j  a  v a  2s .  co  m*/
        IType type = project.findType(fullyQualifiedName);
        return type != null && type.exists();
    } catch (JavaModelException e) {
    }
    return false;
}

From source file:Main.java

protected static String getElementValue(final String xml, final String element) {
    int begin = xml.indexOf("<" + element + ">");
    int end = xml.indexOf("</" + element + ">");
    if (begin < 0 || end < 0 || begin >= end)
        return null;
    return xml.substring(begin + ("<" + element + ">").length(), end);
}

From source file:Main.java

public static String getLocalPart(String s) {
    int i = s.indexOf(':');
    if (i == -1)/*ww  w.  j  a  v  a2s.  co  m*/
        return s;
    return s.substring(i + 1);
}

From source file:Main.java

/**
 * Used to create the base signature text
 * @param url url of the post/*from w  w  w .  j  av a2  s .c om*/
 * @return string of the base signature
 */
static String constructRequestURL(String url) {
    int index = url.indexOf("?");
    if (-1 != index) {
        url = url.substring(0, index);
    }
    int slashIndex = url.indexOf("/", 8);
    String baseURL = url.substring(0, slashIndex).toLowerCase();
    int colonIndex = baseURL.indexOf(":", 8);
    if (-1 != colonIndex) {
        // url contains port number
        if (baseURL.startsWith("http://") && baseURL.endsWith(":80")) {
            // http default port 80 MUST be excluded
            baseURL = baseURL.substring(0, colonIndex);
        } else if (baseURL.startsWith("https://") && baseURL.endsWith(":443")) {
            // http default port 443 MUST be excluded
            baseURL = baseURL.substring(0, colonIndex);
        }
    }
    url = baseURL + url.substring(slashIndex);

    return url;
}

From source file:Main.java

public static boolean containsShortFractions(String __text) {
    for (String key : fractions.keySet()) {
        if (__text.indexOf(fractions.get(key)) > -1)
            return true;
    }// w w  w.  ja v a2  s .co  m
    return false;
}