Example usage for java.lang String lastIndexOf

List of usage examples for java.lang String lastIndexOf

Introduction

In this page you can find the example usage for java.lang String lastIndexOf.

Prototype

public int lastIndexOf(String str) 

Source Link

Document

Returns the index within this string of the last occurrence of the specified substring.

Usage

From source file:Main.java

public static String getFileName(String path) {
    String fileName = path.substring(path.lastIndexOf("/") + 1);
    return fileName;
}

From source file:Main.java

/**
 * Returns the simple name for the class <tt>c</tt>.
 * //from w w w . j  a v a2s  .c o m
 * @param c the class in question
 * @return the simple name for the class <tt>c</tt>
 */
static String simpleName(final Class c) {
    String s = c.getName();
    int ilastDot = s.lastIndexOf(".");
    return ilastDot == -1 ? s : s.substring(ilastDot + 1);
}

From source file:Main.java

public static String getClassNameFromFullQualified(String fullQualified) {
    int lastPoint = fullQualified.lastIndexOf(".");
    if (lastPoint >= 0) {
        return fullQualified.substring(lastPoint + 1);
    } else {/*from ww w. ja  v  a 2  s  .  c  o m*/
        return fullQualified;
    }
}

From source file:Main.java

public static String getFileName(String pathAndName) {
    int start = pathAndName.lastIndexOf("/");
    int end = pathAndName.lastIndexOf(".");
    if (start != -1 && end != -1) {
        return pathAndName.substring(start + 1, end);
    } else {/*w  w w  .j a  v  a2s .c om*/
        return null;
    }

}

From source file:Main.java

public static String getPrefix(String nodeName) {
    int index = nodeName.lastIndexOf(58);
    if (index == -1) {
        return null;
    } else {/*from   ww w .  jav a2  s.  c om*/
        return nodeName.substring(0, index);
    }
}

From source file:Main.java

private static String delQuot(String s) {
    return s.substring(s.indexOf('"') + 1, s.lastIndexOf('"'));
}

From source file:Main.java

public static Map<String, String> url2Map(String url) {
    url = url.substring(url.lastIndexOf("?") + 1);
    String[] params = url.split("&");
    Map<String, String> map = new HashMap<String, String>();
    for (String param : params) {
        map.put(param.split("=")[0], param.split("=")[1]);
    }// w w  w.  j  a v a2s  .  c o  m
    return map;
}

From source file:Main.java

public static String shortClassName(Class c) {
    String clss = c.getName();
    int inx = clss.lastIndexOf('.');
    if (inx >= 0)
        clss = clss.substring(inx + 1);//  w w  w.  j  a v  a2 s.  c om
    return clss;
}

From source file:Main.java

private static String getHash(String s) {
    String next = s.substring(s.lastIndexOf("/"), s.length());
    if (next.length() < 5) {
        return getHash(s.replace(next, ""));
    } else {/*from w w w  . j  a v a2  s  .  c o m*/
        return next;
    }

}

From source file:Main.java

public static String getLocalName(String nodeName) {
    int index = nodeName.lastIndexOf(58);
    if (index == -1) {
        return nodeName;
    } else {// w  w w  .  j a  v a2s  .c  o m
        return nodeName.substring(index + 1, nodeName.length());
    }
}