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 clearSuffix(String str) {
    int i = str.lastIndexOf(".");
    if (i != -1) {
        return str.substring(0, i);
    }//from   w ww .  j  av  a2 s  . c  om
    return str;
}

From source file:Main.java

public static String getFileNameWithoutExt(String filename) {
    if (filename.lastIndexOf(".") != -1 && filename.lastIndexOf(".") != filename.length() - 1) {
        return filename.substring(0, filename.lastIndexOf("."));
    }//w  w  w . j  a  v a2s . co m
    return filename;

}

From source file:Main.java

public static String getPathFromFilepath(String path) {
    int index = path.lastIndexOf(File.separator);
    String p = File.separator;
    if (index != -1) {
        p = path.substring(0, index);/*ww w. jav  a 2s.c o m*/
    }
    return p;
}

From source file:Main.java

protected static String[] getClassAndFieldNames(String path) {
    int lastDot = path.lastIndexOf('.');
    String className = lastDot < 0 ? "" : path.substring(0, lastDot < 0 ? 1 : lastDot).replace('.', '$');
    String fieldName = lastDot < 0 ? path : path.substring(lastDot + 1);
    return new String[] { className, fieldName };
}

From source file:Main.java

public static String fileNameAppend(String name, String apd) {
    int i = name.lastIndexOf(".");
    if (i == -1 || i == 0)
        return name + apd;
    return name.substring(0, i) + apd + name.substring(i, name.length());
}

From source file:Main.java

public static String getTitleFromPath(String path) {
    int startIndex = path.lastIndexOf("/");
    int endIndex = path.lastIndexOf(".");
    if (startIndex < 0 || endIndex < 0) {
        return "";
    }//from  w  w  w  .  j  a v a2  s. c  om
    return path.substring(startIndex + 1, endIndex);
}

From source file:Main.java

/**
 * Returns a copy of the given path with the extension omitted.
 *
 * @param path the path/*from  w w  w  .ja v  a  2s . co m*/
 * @return path, with the extension elements omitted.
 */
public static String trimOffExtension(String path) {
    int lastSlash = path.lastIndexOf('/');
    int lastDot = path.lastIndexOf('.');
    return (lastDot > lastSlash) ? path.substring(0, lastDot) : path;
}

From source file:Main.java

public static String parentXpath(String xpath) {
    int lastIndexOf = xpath.lastIndexOf("/");
    if (lastIndexOf == -1) {
        lastIndexOf = xpath.length();//from   w ww .  j ava  2s. c o m
    }
    return xpath.substring(0, lastIndexOf);
}

From source file:Main.java

public static String removeFileNameSuffix(String srcName) {
    int dotIndex = srcName.lastIndexOf(".");
    if (dotIndex == -1)
        return srcName;
    else/* w  w w  .  j  a v a2  s.  c  o  m*/
        return srcName.substring(0, dotIndex);
}

From source file:Main.java

public static Long getIndexFromName(String name) {
    int last = name.lastIndexOf("-");
    String aux = name.substring(last + 1);
    long r = 0;//from   w  ww  .  j  ava  2 s  . c  o  m
    try {
        r = Long.parseLong(aux);
        return new Long(r);
    } catch (Exception ex) {
        return null;
    }
}