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 String getMiddleString(String source, String start, String end) {
    int start_idx = source.indexOf(start) + start.length();
    int end_idx = 0;
    if (end.isEmpty()) {
        end_idx = source.length();/*from   ww  w .jav a2s . c  o m*/
    } else {
        end_idx = source.indexOf(end, start_idx);
        if (end_idx <= 0) {
            end_idx = source.length();
        }
    }

    if (start_idx <= 0 || end_idx <= 0 || end_idx <= start_idx) {

        return null;
    }

    return source.substring(start_idx, end_idx);
}

From source file:Main.java

public static int count(String str, String substring) {
    int c = 0;/*from  w  w  w  .  jav  a 2 s. c  om*/
    int index1 = str.indexOf(substring);
    if (index1 >= 0) {
        c++;
        c += count(str.substring(index1 + substring.length()), substring);
    }
    return c;
}

From source file:Main.java

public static String ensureUnique(Set<String> nameSet, String name) {
    String paramName = name;
    if (null != paramName && -1 != paramName.indexOf(".")) {
        paramName = paramName.replace('.', '_');
    }/* ww w .  j  ava 2s .  c  o  m*/
    if (nameSet.contains(paramName)) {
        int index = 1;
        String tempVar = null;
        while (true) {
            tempVar = paramName + "_" + index;
            if (!nameSet.contains(tempVar)) {
                break;
            }
            index++;
        }
        paramName = tempVar;
    }
    return paramName;
}

From source file:Utils.java

/**
 * Creates a QName instance from the given namespace context for the given qualifiedName
 *
 * @param element       the element to use as the namespace context
 * @param qualifiedName the fully qualified name
 * @return the QName which matches the qualifiedName
 *//*from   w w w.j ava  2 s  .  co  m*/
public static QName createQName(Element element, String qualifiedName) {
    int index = qualifiedName.indexOf(':');
    if (index >= 0) {
        String prefix = qualifiedName.substring(0, index);
        String localName = qualifiedName.substring(index + 1);
        String uri = recursiveGetAttributeValue(element, "xmlns:" + prefix);
        return new QName(uri, localName, prefix);
    } else {
        String uri = recursiveGetAttributeValue(element, "xmlns");
        if (uri != null) {
            return new QName(uri, qualifiedName);
        }
        return new QName(qualifiedName);
    }
}

From source file:Main.java

public static String scrape(String resp, String start, String stop) {
    int offset, len;
    if ((offset = resp.indexOf(start)) < 0)
        return "";
    if ((len = resp.indexOf(stop, offset + start.length())) < 0)
        return "";
    return resp.substring(offset + start.length(), len);
}

From source file:Main.java

/**
 * @param the/*from  w ww .j  a  v a2  s  .c o  m*/
 *            node to create the name from, never <code>null</code>
 * @return the node of the name as qualified name, never <code>null</code>
 */
public static QName buildQName(Node node) {
    String localPart;
    String nsName;
    String name = node.getTextContent();
    int indexOfColon = name.indexOf(':');
    if (indexOfColon > 0) {
        localPart = name.substring(indexOfColon + 1);
        nsName = node.lookupNamespaceURI(name.substring(0, indexOfColon));
    } else {
        localPart = name;
        // return default namespace URI if any
        nsName = node.lookupNamespaceURI(null);
    }
    return new QName(nsName, localPart);
}

From source file:Main.java

public static String substringBetweenEnclose(String text, String start, String end) {
    final int nStart = text.indexOf(start);
    final int nEnd = text.lastIndexOf(end);
    if ((nStart != -1) && (nEnd != -1) && (nEnd > (nStart + start.length()))) {
        return text.substring(nStart + start.length(), nEnd);
    } else {/*from w w  w.j  a v  a2  s  .co m*/
        return null;
    }
}

From source file:no.met.jtimeseries.meteogram.AbstractChart.java

/**
 * Get the value of a parameters./* w w w.  j  ava 2  s  .co m*/
 * @param record The String of parameter in url command, like "temperature=true"
 * @return The value after =
 */
static String getValueOf(String record) {
    return record.substring(record.indexOf("=") + 1);
}

From source file:Main.java

public static boolean containsWildCard(String s) {
    return (s.indexOf('*') >= 0 || s.indexOf('?') >= 0);
}

From source file:Main.java

public static int IPAddr2int(String IPAddr) {
    byte[] ip = new byte[4];
    int position1 = IPAddr.indexOf(".");
    int position2 = IPAddr.indexOf(".", position1 + 1);
    int position3 = IPAddr.indexOf(".", position2 + 1);
    ip[0] = Byte.parseByte(IPAddr.substring(0, position1));
    ip[1] = Byte.parseByte(IPAddr.substring(position1 + 1, position2));
    ip[2] = Byte.parseByte(IPAddr.substring(position2 + 1, position3));
    ip[3] = Byte.parseByte(IPAddr.substring(position3 + 1));
    return bytes2int(ip, 0);
}