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 QName convertStringToQName(String expandedQName, String prefix) {
    int ind1 = expandedQName.indexOf('{');
    if (ind1 != 0) {
        return new QName(expandedQName);
    }/*from www . j  ava2  s  . c  o m*/

    int ind2 = expandedQName.indexOf('}');
    if (ind2 <= ind1 + 1 || ind2 >= expandedQName.length() - 1) {
        return null;
    }
    String ns = expandedQName.substring(ind1 + 1, ind2);
    String localName = expandedQName.substring(ind2 + 1);
    return new QName(ns, localName, prefix);
}

From source file:Main.java

public static String substringBetweenNarrow(String text, String start, String end) {
    final int nEnd = text.indexOf(end);
    int nStart = -1;
    if (nEnd != -1) {
        nStart = text.lastIndexOf(start, nEnd - 1);
    }/*from www .j  a va  2  s.  c o m*/
    if ((nStart < nEnd) && (nStart != -1) && (nEnd != -1)) {
        return text.substring(nStart + start.length(), nEnd);
    } else {
        return null;
    }
}

From source file:Main.java

public static String getTwitterUserFromUrl(String sourceUrl) {
    String user = sourceUrl.replaceFirst("#!/", "");
    int index = user.indexOf(".com/");
    if (index > 0) {
        index += ".com/".length();
        int index2 = user.indexOf("/", index);
        if (index2 < 0)
            index2 = user.length();//from   w  w w. j  a  va2  s .com

        user = user.substring(index, index2);
    }
    return user.toLowerCase();
}

From source file:Main.java

public static String getConditionOfExpression(String expression) {
    // pattern for conditions
    Pattern conditionPattern = Pattern
            .compile("^([\\w\\W&&[^/\\[\\]]]+)?(\\[[\\w\\W&&[^\\[\\]]]+\\])(/[\\w\\W]+)?$");
    Matcher conditionMatcher = conditionPattern.matcher(expression);
    if (conditionMatcher.find() && (conditionMatcher.group().length() == expression.length())) {
        StringTokenizer st = new StringTokenizer(expression, "]");
        String condition = st.nextToken();
        condition = condition.substring(condition.indexOf("[") + 1);
        return condition;
    }/*w w w. ja v  a  2 s .c om*/
    return null;
}

From source file:Main.java

/**
 * Returns user name from given jid//from   w w  w . j ava 2 s . com
 * */
public static String parseBareName(final String jid) {
    if (jid == null)
        return null;

    int indx = jid.indexOf('@');

    return jid.substring(0, indx < 0 ? jid.length() : indx);
}

From source file:Main.java

/**
 * Returns jid address without resource specifier
 * *///from   w  ww . ja va  2s  . c o  m
public static String parseBareJid(final String jid) {
    if (jid == null)
        return null;

    int indx = jid.indexOf('/');

    return jid.substring(0, indx < 0 ? jid.length() : indx);
}

From source file:com.amazonaws.services.logs.connectors.elasticsearch.ElasticsearchTransformerUtils.java

/**
 * Checks if the substring from the first occurrence of { is valid json and
 * returns the substring. Otherwise returns null.
 *///from   ww  w . j a v a 2s . co m
public static String extractJson(String message) {
    int jsonStart = message.indexOf("{");

    if (jsonStart < 0) {
        return null;
    }

    String jsonSubString = message.substring(jsonStart);

    try {
        JsonNode rootNode = JSON_OBJECT_MAPPER.readTree(jsonSubString);
        if (rootNode.isValueNode()) {
            return null;
        }
    } catch (IOException e) {
        return null;
    }
    return jsonSubString;
}

From source file:Main.java

public static JSONObject convertStringToJSON(String jsonString) throws JSONException {
    String secureJSONString = jsonString.substring(jsonString.indexOf("{"), jsonString.lastIndexOf("}") + 1);
    JSONObject jsonObject = new JSONObject(secureJSONString);
    return jsonObject;
}

From source file:Main.java

public static Map<String, String> split(List<String> list, String separator) {
    if (list == null) {
        return null;
    }//  w  w w. j a v  a 2s  . c  om
    Map<String, String> map = new HashMap<String, String>();
    if (list == null || list.size() == 0) {
        return map;
    }
    for (String item : list) {
        int index = item.indexOf(separator);
        if (index == -1) {
            map.put(item, "");
        } else {
            map.put(item.substring(0, index), item.substring(index + 1));
        }
    }
    return map;
}

From source file:Main.java

/**
 * Parse the tile # from the read name.//w  w w .  ja v a  2s .c o m
 * If we find that there are other elements needed from the read name, it might be a good idea to put
 * makeReadName() and various get..() methods into a new class.
 *
 * @param readName As produced by IlluminaUtil.makeReadName()
 * @return tile number, or null if read name is not in correct format.
 */
public static Integer getTileFromReadName(final String readName) {
    final int first = readName.indexOf(':');
    if (first > 0) {
        final int second = readName.indexOf(':', first + 1);
        if (second > 0) {
            final int third = readName.indexOf(':', second + 1);
            if (third > 0) {
                return Integer.parseInt(readName.substring(second + 1, third));
            }
        }
    }

    return null;
}