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 getFileSubFix(String fileName) {
    int index1 = fileName.lastIndexOf(File.separatorChar);
    int index2 = fileName.lastIndexOf(".");
    if (index2 <= index1)
        return "";
    return fileName.substring(index2 + 1);
}

From source file:Main.java

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

From source file:Main.java

public static String getFilePreName(String fileName) {
    int index = fileName.lastIndexOf(".");
    if (index == -1) {
        return fileName;
    } else {/*  w  ww  . j  a  va2  s. com*/
        return fileName.substring(0, index);
    }
}

From source file:Main.java

public static String getFileExtension(String sFileName) {
    int dotIndex = sFileName.lastIndexOf('.');
    if (dotIndex == -1) {
        return null;
    }//from   w w  w.  j  a v a  2  s  . c  om
    return sFileName.substring(dotIndex);
}

From source file:Main.java

public static String getFilename(String urlpath) {
    return urlpath.substring(urlpath.lastIndexOf("/") + 1, urlpath.length());
}

From source file:Main.java

public static String getFileExtensionWithoutDot(String file) {
    return file.substring(file.lastIndexOf(".") + 1);
}

From source file:Main.java

public static String removeSuffix(String fileName) {
    int index = fileName.lastIndexOf(".");

    if (index == -1) {
        return fileName;
    } else {/*from w w  w  .  j  av a 2  s  .  c  o m*/
        return fileName.substring(0, index);
    }
}

From source file:Main.java

public static String getPathName(String absolutePath) {
    int start = absolutePath.lastIndexOf(File.separator) + 1;
    int end = absolutePath.length();
    return absolutePath.substring(start, end);
}

From source file:Main.java

private @Nullable static String extractExtension(String path) {
    int pos = path.lastIndexOf('.');
    if (pos < 0 || pos == path.length() - 1) {
        return null;
    }/*www .  ja v  a  2  s  .c om*/
    return path.substring(pos + 1);
}

From source file:Main.java

public static String getExtension(String pathOrUrl) {
    int dotPos = pathOrUrl.lastIndexOf('.');
    if (0 <= dotPos) {
        return pathOrUrl.substring(dotPos + 1);
    } else {//from  w w  w .j av  a2 s. com
        return "ext";
    }
}