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

/**
 * Remove path information from a filename returning only its file component
 * //from w w w  . java  2  s  . c om
 * @param filename
 *            The filename
 * @return The filename sans path information
        
 */
public static String fileComponent(String filename) {
    int i = filename.lastIndexOf(File.separator);
    return (i > -1) ? filename.substring(i + 1) : filename;
}

From source file:Main.java

public static String getLastPathComponent(String url) {

    int index = url.lastIndexOf("/");
    if (index > 0)
        return url.substring(url.lastIndexOf("/") + 1, url.length());

    return url;//from w w  w. j av  a2 s .  c  o m

}

From source file:Main.java

/**
 * Get the file extension of the file so data type can be identified
 * @param url the url of the file address
 * @return the file extension//from ww w  . ja  v a 2  s .  c om
 */
public static String getFileExtension(String url) {
    String extension = url.substring(url.lastIndexOf(".") + 1);
    extension = extension.toLowerCase();
    return extension;
}

From source file:Main.java

/**
 * @param tag   e.g., tr//from   w  ww.  j  a  va2  s . co  m
 * @param xpath e.g., /html/body/table[1]/tr[2]/td[2]
 * @return /html/body/table[1]/tr[2]
 */
public static String trimXPathLastTag(String tag, String xpath) {
    int lastTagIndex = xpath.lastIndexOf(tag);
    if (lastTagIndex != -1) {
        int end = xpath.indexOf("/", lastTagIndex);
        if (end == -1) {
            return xpath;
        }
        return xpath.substring(0, end);
    }
    return null;
}

From source file:Main.java

/**
 * Strip a filename of its <i>last</i> extension (the portion immediately
 * following the last dot character, if any)
 * //from  w w w .  ja v  a2  s.  c om
 * @param filename
 *            The filename
 * @return The filename sans extension
        
 */
public static String baseName(String filename) {
    int i = filename.lastIndexOf('.');
    return (i > -1) ? filename.substring(0, i) : filename;
}

From source file:Main.java

public static String getJIDWithoutResource(String jid) {
    if (jid != null && jid.length() > 0 && jid.lastIndexOf("/") > 1)
        return jid.substring(0, jid.lastIndexOf("/"));
    return jid;/* w w  w.  j  a v a 2s . co m*/
}

From source file:Main.java

public static String cutImagePath(String url) {
    String res = "";
    int start = url.lastIndexOf("/") + 1;
    res = url.substring(start);//  w  ww  .j  a  va2  s  .c  o m
    return res;
}

From source file:Utils.java

public static String nonPackageQualifiedName(final Class<?> clazz) {

    String name = clazz.getName();
    return name.substring(name.lastIndexOf('.') + 1);
}

From source file:Main.java

public static String basename(final String path) {
    String s = path;
    final int i = s.lastIndexOf('/');
    if (i != -1)/*from  ww  w . j  a va  2  s  . c  om*/
        s = s.substring(i + 1);
    return s;
}

From source file:FileUtil.java

public static String getFileExtension(String fileName) {
    return fileName.substring(fileName.lastIndexOf('.') + 1);
}