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

static public Element selectSingleElement(Element element, String xpathExpression) throws Exception {
    if (xpathExpression.indexOf("/") == -1) {
        NodeList nodeList = element.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(xpathExpression)) {
                return (Element) node;
            }/*from   ww  w. j a v  a2 s  . co  m*/
        }
        //  NodeList nodes = element.getElementsByTagName(xpathExpression);
        //  if (nodes.getLength() > 0) {
        //      return (Element) nodes.item(0);
        //  } else {
        return null;
        //  }
    } else {
        XPath xpath = XPathFactory.newInstance().newXPath();
        Element node = (Element) xpath.evaluate(xpathExpression, element, XPathConstants.NODE);
        return node;
    }
}

From source file:Main.java

/**
 * Devuelve el nombre lindo de una pagina a partir
 * del path de la pagina (preferentemente el absoluto)
 * Ej: "MiPaginaConNombreLindo"/* w  w w .  j  a  v a  2  s  .c  o  m*/
 */
public static String getPageNiceName(String path) {
    File original = new File(path);
    String pageName = original.getName();
    pageName = pageName.substring(0, pageName.indexOf("."));
    return capitalize(pageName);
}

From source file:Main.java

public static String getOnlyIdOfXmiAttribute(NodeList elements, int i) {
    Node href = elements.item(i).getAttributes().getNamedItem("href");
    if (href != null) {
        String currentValue = href.getNodeValue();
        return currentValue.substring(currentValue.indexOf("#") + 1, currentValue.length());
    } else {/*from  w ww.  j a  v a2  s.c om*/
        return null;
    }
}

From source file:Main.java

public static String remove(String str, char remove) {
    if (isEmpty(str) || str.indexOf(remove) == -1) {
        return str;
    }//w ww.j a  va 2 s .com
    char[] chars = str.toCharArray();
    int pos = 0;
    for (int i = 0; i < chars.length; i++) {
        if (chars[i] != remove) {
            chars[pos++] = chars[i];
        }
    }
    return new String(chars, 0, pos);
}

From source file:Main.java

private static String _doubleErasure(TypeMirror elementType, Types typeUtils) {
    String name = typeUtils.erasure(elementType).toString();
    int typeParamStart = name.indexOf('<');
    if (typeParamStart != -1) {
        name = name.substring(0, typeParamStart);
    }/*  w w w .j  a  va 2  s . c o m*/
    return name;
}

From source file:Main.java

protected static Set intersectEmail(Set permitted, String email) {
    String _sub = email.substring(email.indexOf('@') + 1);

    if (permitted.isEmpty()) {
        permitted.add(_sub);/*from ww  w.  j av a 2 s  . c  om*/

        return permitted;
    } else {
        Set intersect = new HashSet();

        Iterator _iter = permitted.iterator();
        while (_iter.hasNext()) {
            String _permitted = (String) _iter.next();

            if (_sub.endsWith(_permitted)) {
                intersect.add(_sub);
            } else if (_permitted.endsWith(_sub)) {
                intersect.add(_permitted);
            }
        }

        return intersect;
    }
}

From source file:Main.java

public static int setMusicType(String msg) {
    int result = 0;
    if (msg.indexOf(".mp3") != -1) {

    }/* w  w w . j av  a  2  s. c o  m*/

    else if (msg.indexOf(".mid") != -1) {

    }

    else if (msg.indexOf(".mid") != -1) {

    }

    else if (msg.indexOf(".mid") != -1) {

    }

    return result;
}

From source file:Main.java

public static String stringReplace(String str, String what, String replacement) {
    int i = str.indexOf(what);

    if (i >= 0) {
        int j = 0;
        int whatLen = what.length();
        StringBuilder result = new StringBuilder();

        do {//from   w  w  w  . jav a  2s.c  om
            result.append(str.substring(j, i));
            result.append(replacement);

            j = i + whatLen;
            i = str.indexOf(what, j);
        } while (i >= 0);

        result.append(str.substring(j));

        return result.toString();
    } else {
        return str;
    }
}

From source file:Main.java

private static boolean isBrowseable(String mediaID) {
    return mediaID.indexOf(LEAF_SEPARATOR) < 0;
}

From source file:Main.java

public static boolean compress(File file) {
    try {/*from w  w w .j  a v  a  2  s  .  c om*/
        String fileName = file.getName();
        if (fileName.indexOf(".") != -1)
            fileName = fileName.substring(0, fileName.indexOf("."));
        FileOutputStream f = new FileOutputStream(file.getParent() + "/" + fileName + ".zip");
        CheckedOutputStream cs = new CheckedOutputStream(f, new Adler32());
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(cs));
        InputStream in = new FileInputStream(file);
        out.putNextEntry(new ZipEntry(file.getName()));
        int len = -1;
        byte buf[] = new byte[1024];
        while ((len = in.read(buf, 0, 1024)) != -1)
            out.write(buf, 0, len);
        out.closeEntry();

        in.close();
        out.close();
        return true;
    } catch (Exception e) {
        return false;
    }
}