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

/**
 * get full path/* w ww.  j  av a  2 s.  c o  m*/
 * 
 * @param filepath
 * @return
 */
public static String acquireNameFromFilepath(String filepath) {
    int pos = filepath.lastIndexOf('/');
    if (pos != -1) {
        return filepath.substring(pos + 1);
    }
    return "";
}

From source file:Main.java

/**
 * Returns file name without path information.
 * //from   w ww  .  jav a  2  s.  co  m
 * @param filename
 * @return
 */
public static String shortFilename(String filename) {
    int pos = filename.lastIndexOf(java.io.File.separatorChar);
    if (pos != -1)
        return filename.substring(pos + 1);
    else
        return filename;
}

From source file:Main.java

public static String getNameFromFilepath(String path) {
    int index = path.lastIndexOf(File.separator);
    String name = "";
    if (index != -1) {
        name = path.substring(index + 1);
    } else {/*  w  ww. ja v a2  s  . c  o  m*/
        name = path;
    }
    return name;
}

From source file:Main.java

public static String getNameFromFilename(String filename) {
    int dotPosition = filename.lastIndexOf('.');
    if (dotPosition != -1) {
        return filename.substring(0, dotPosition);
    }//from  ww w  . j  ava  2s .co  m
    return "";
}

From source file:Main.java

public static String[] analyseMethod(String methodName) {
    int index = methodName.lastIndexOf(".");
    String classPath = methodName.substring(0, index);
    String method = methodName.substring(index + 1, methodName.length());
    String[] strings = new String[2];
    strings[0] = classPath;/*ww  w . j  a v  a  2  s  . c  om*/
    strings[1] = method;
    return strings;
}

From source file:Main.java

public static String getFileExtension(String fileName) {
    int i = fileName.lastIndexOf('.');
    int p = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));
    if (i > p) {
        return fileName.substring(i + 1);
    }/*from w ww  . j a  v  a 2s.  c om*/
    return "";
}

From source file:Main.java

/**
 * Returns the package name part of an dot-qualified class name.
 *
 * @param qualifiedName  qualified class name
 * @return  package name//from   w  w w  .j  av  a2  s  .  c  om
 */
public static String getPackageName(String qualifiedName) {
    int index = qualifiedName.lastIndexOf('.');
    return index < 0 ? "" : qualifiedName.substring(0, index);
}

From source file:Main.java

public static String removeLastStep(String xpStr) {
    int lastSlash = xpStr.lastIndexOf("/");

    if (lastSlash != -1) {
        xpStr = xpStr.substring(0, lastSlash);
    }/*from   w w w .  j a  v a2  s  .c  om*/

    return xpStr;
}

From source file:Main.java

public static String getExtFromFilename(String filename) {
    int dotPosition = filename.lastIndexOf('.');
    if (dotPosition != -1) {
        return filename.substring(dotPosition + 1, filename.length());
    }//w ww  . ja v a  2 s .c o m
    return "";
}

From source file:Main.java

private static String getFileExtension(String fileName) {
    return fileName.substring(fileName.lastIndexOf(".") + 1);
}