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

/**
 * Returns the prefix of a specified QName.
 * /*w ww. j  av  a2  s  .  c  om*/
 * @param qname
 *            the specified QName in string, e.g. ns:value
 * @return the prefix of the QName, e.g. ns
 */
public static String getPrefixOfQName(String qname) {
    int index = qname.indexOf(':');
    if (index < 0) {
        return null;
    } else {
        return qname.substring(0, index);
    }
}

From source file:Main.java

public static final String appendFileName(String file, String suffix) {
    int indexOf = file.indexOf('.');
    return file.substring(0, indexOf) + suffix + file.substring(indexOf);
}

From source file:Main.java

/**
 * Returns the local part of a specified QName.
 * /*ww w.  j a v a2s.com*/
 * @param qname
 *            the specified QName in string, e.g. ns:value
 * @return the local part of the QName, e.g. value
 */
public static String getLocalPartOfQName(String qname) {
    int index = qname.indexOf(':');
    if (index < 0) {
        return qname;
    } else {
        return qname.substring(index + 1);
    }
}

From source file:Main.java

public static boolean tieneCabecera(String documento) {
    if (documento.indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") == 0)
        return true;
    if (documento.indexOf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>") == 0)
        return true;
    return false;
}

From source file:Main.java

public static String hostFromUrl(String url) {
    String host = url;
    int index = host.indexOf("://");
    if (index != -1) {
        host = host.substring(index + 3);
    }//  w w w  . j a va 2  s .  co  m
    index = host.indexOf("/");
    if (index != -1) {
        host = host.substring(0, index);
    }
    return host;
}

From source file:Main.java

public static int toPathIndex(String fileName) {
    int point = fileName.indexOf('/');
    if (point == -1) {
        point = fileName.indexOf('\\');
    }/*from  www .  ja v a 2  s .  co m*/
    return point;
}

From source file:Main.java

public static String fileExt(String url) {
    String ext = url.substring(url.lastIndexOf("."));
    if (ext.indexOf("?") > -1) {
        ext = ext.substring(0, ext.indexOf("?"));
    }//w w w.  j  a  v  a2  s. c o  m
    if (ext.indexOf("%") > -1) {
        ext = ext.substring(0, ext.indexOf("%"));
    }
    return ext;
}

From source file:Main.java

/**
 * from "myFunction(arg1,arg2)", return ["arg1","arg2"]
 *//*w  w  w .j  a v  a  2s  .  c  om*/
public static String[] getAttributes(String tag) {
    String attributes = tag.substring(tag.indexOf('(') + 1, tag.lastIndexOf(')'));
    if (attributes.isEmpty())
        return new String[0];
    return trim(attributes.split(","));
}

From source file:Main.java

/**
 * by Jesse Gallegher//  www.jav a2s . c o m
 * 
 */

public static String strLeft(String input, String delimiter) {
    return input.substring(0, input.indexOf(delimiter));
}

From source file:Main.java

public static Map<String, String> parseOAuthResponse(String content) {
    Map<String, String> map = new HashMap<String, String>();
    if (content != null && !content.isEmpty()) {
        String[] items = content.split("&");
        for (String item : items) {
            int index = item.indexOf("=");
            String key = item.substring(0, index);
            String value = item.substring(index + 1);
            map.put(key, value);//from   w w w.  ja v a 2s.com
        }
    }
    return map;
}