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

/**
 * @see java.util.regex.Matcher#quoteReplacement(java.lang.String)
 *///from   www  .  j ava  2  s .  c o m
public static String quoteReplacement(String s) {
    if ((s.indexOf('\\') == -1) && (s.indexOf('$') == -1))
        return s;
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c == '\\') {
            sb.append('\\');
            sb.append('\\');
        } else if (c == '$') {
            sb.append('\\');
            sb.append('$');
        } else {
            sb.append(c);
        }
    }
    return sb.toString();
}

From source file:Main.java

private static boolean isFileProtocol(String href) {
    // Test for file: or /file:
    int index = href.indexOf("file:"); //$NON-NLS-1$
    return (index == 0 || (index == 1 && href.charAt(0) == '/'));
}

From source file:Main.java

public static final void appendCookies(final StringBuffer cookie, final HttpURLConnection conn) {
    List<String> values = conn.getHeaderFields().get("Set-Cookie");
    if (values != null) {
        for (String v : values) {
            if (v.indexOf("deleted") == -1) {
                if (cookie.length() > 0) {
                    cookie.append("; ");
                }//from www .  j av  a 2s.com
                cookie.append(v.split(";")[0]);
            }
        }
    }
}

From source file:Main.java

public static String[] split(String paramString1, String paramString2) {
    int i = paramString1.indexOf(paramString2);
    if (i == -1)// ww  w  .  java2  s.  c om
        return new String[] { paramString1 };
    ArrayList localArrayList = new ArrayList();
    int j = 0;
    while (i != -1) {
        localArrayList.add(paramString1.substring(j, i));
        j = i + paramString2.length();
        i = paramString1.indexOf(paramString2, j);
    }
    if (j != paramString1.length())
        localArrayList.add(paramString1.substring(j));
    return (String[]) localArrayList.toArray(new String[localArrayList.size()]);
}

From source file:Main.java

public static boolean hasWildcards(String value) {
    return value.indexOf('*') != -1;
}

From source file:Main.java

public static String getHostName(String urlString) {
    String head = "";
    int index = urlString.indexOf("://");
    if (index != -1) {
        head = urlString.substring(0, index + 3);
        urlString = urlString.substring(index + 3);
    }//from ww w .j av  a 2 s. c om
    index = urlString.indexOf("/");
    if (index != -1) {
        urlString = urlString.substring(0, index + 1);
    }
    return head + urlString;
}

From source file:Main.java

public static Element[] getSubChildElement(Element ele, String tagname) {
    int p0 = tagname.indexOf(':');
    if (p0 >= 0)
        tagname = tagname.substring(p0 + 1);

    return getSubChildElement(ele, new String[] { tagname });
}

From source file:Main.java

public static String replace(String source, String subject, String object) {
    StringBuffer rtnStr = new StringBuffer();
    String preStr = "";
    String nextStr = source;//w  ww  . ja  v  a  2  s . c o m
    String srcStr = source;

    while (srcStr.indexOf(subject) >= 0) {
        preStr = srcStr.substring(0, srcStr.indexOf(subject));
        nextStr = srcStr.substring(srcStr.indexOf(subject) + subject.length(), srcStr.length());
        srcStr = nextStr;
        rtnStr.append(preStr).append(object);
    }
    rtnStr.append(nextStr);
    return rtnStr.toString();
}

From source file:org.openmrs.module.sdmxhddataexport.web.controller.query.QueryValidator.java

private static int countSubStr(String source, String find) {
    int index = source.indexOf(find);
    int count = 0;
    while ((index < source.length()) && (index >= 0)) {
        count++;//from w w w  . ja  va 2 s .c  o  m
        index = source.indexOf(find, index + 1);
    }
    return count;
}

From source file:mailbox.IMAPMessageUtil.java

public static String getIdLeftFromMessageId(String messageId) {
    int start = messageId.indexOf('<');
    int at = messageId.indexOf('@');
    return messageId.substring(start + 1, at).trim().replaceFirst("^/", "");
}