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 getPrefix(String s) {
    int i = s.indexOf(':');
    if (i == -1)// w  w  w  . j av  a  2s  .com
        return null;
    return s.substring(0, i);
}

From source file:Main.java

/**
 * @param nombreEtiqueta Nombre de la etiqueta que hemos de comprobar si contiene sin los s&iacute;mbolos de aportura y cierre: < >
 * @param documento Documento XML con o sin cabecera,  para el cual queremos comprobar si tiene la etiqueta
 * @return true si el documento contiene a la etiqueta.
 *///from   w w  w.  ja  v  a2s  .c om
public static boolean contieneEtiqueta(String nombreEtiqueta, String documento) {
    if (documento.indexOf("<" + nombreEtiqueta + ">") != -1)
        return true;
    return false;
}

From source file:Main.java

public static String aniadeCabecera(String documento) {
    if (documento.indexOf("<?xml version=\"1.0\"") != -1) //si tiene cabecera ni lo tocamos
        return documento;
    return (new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append(documento)).toString();
}

From source file:Main.java

public static String getAddressFromNameAddress(String nameAddress) {
    return nameAddress.substring(nameAddress.indexOf(" ") + 1);
}

From source file:Main.java

private static String normalizeSelector(String selector) {
    while (selector.indexOf("  ") != -1) {
        selector = selector.replaceAll("  ", " ");
    }/* ww  w  . j  av a 2 s. c o m*/
    selector = selector.replaceAll(" \\+ ", "\\+");
    selector = selector.replaceAll(" \\> ", "\\>");
    return selector;
}

From source file:Main.java

public static String getAfterSeparatorOrAll(String name) {
    int index = name.indexOf(SEPARATOR);
    if (index == -1)
        return name;
    else//from  w  ww.j  ava  2s  . c  om
        return name.substring(index + 1);
}

From source file:Main.java

public static String getBeforeSeparatorOrNothing(String name) {
    int index = name.indexOf(SEPARATOR);
    if (index == -1 || name.startsWith(SEPARATOR))
        return "";
    else//from  w  w w .ja va  2s  .c om
        return name.substring(0, index);
}

From source file:Main.java

public static String getAfterSeparatorOrNothing(String name) {
    int index = name.indexOf(SEPARATOR);
    if (index == -1)
        return "";
    else/*from   w ww  .j ava2 s .  c  o  m*/
        return name.substring(index + 1);
}

From source file:Main.java

public static boolean contains(String line, String s) {
    return line.indexOf(s) >= 0;
}

From source file:Main.java

public static String parseCookie(String rawCookie) {
    int indexStart = rawCookie.indexOf("JSESSIONID=");
    if (indexStart >= 0) {
        int indexStop = rawCookie.indexOf(";", indexStart);
        if (indexStop >= 0 && indexStop > indexStart) {
            return rawCookie.substring(indexStart, indexStop);
        }/*from   w w  w.  j av a 2 s. com*/
    }
    return "";
}