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

/**
 * Path manipulation.//ww  w . j  a  v  a 2 s  .  c  o  m
 *
 * @param nodePath
 * @return
 */
public static String getParentPath(String nodePath) {
    // add for report
    if (nodePath.lastIndexOf(":") == -1) {
        return nodePath;
    }

    //
    return nodePath.substring(0, nodePath.lastIndexOf(":"));
}

From source file:Main.java

public static void makeDirsByFilePath(String filePath) {
    String path = filePath.substring(0, filePath.lastIndexOf("/"));
    makeDirsByPath(path);//from w  ww  .  ja va  2  s.c  om
}

From source file:Main.java

/**
 * Parse a filename from the given URI./*  ww  w .  j  a  va  2  s  .co  m*/
 *
 * @param uri a uri
 * @return a filename if the uri ends with just a resource, null otherwise
 */
public static final String getFilenameFromURI(URI uri) {
    String path = uri.getPath();
    int lastSlash = path.lastIndexOf('/');

    // Is the last slash at the end?
    if (lastSlash == path.length() - 1) {
        return null;
    }
    return path.substring(lastSlash + 1);
}

From source file:Main.java

/**
 *
 * @param nodePath// ww  w . j a  v a  2  s.co m
 * @return
 */
public static int getChildPosition(String nodePath) {
    return Integer.parseInt(nodePath.substring(nodePath.lastIndexOf(":") + 1));
}

From source file:Main.java

/**
 * Get the short name of the specified class by striping off the package name.
 * // www  .j a va 2 s. co m
 * @param classname
 *          Class name.
 * @return Short class name.
 */
public static String stripPackageName(final String classname) {
    int idx = classname.lastIndexOf(PACKAGE_SEPARATOR);

    if (idx != -1)
        return classname.substring(idx + 1, classname.length());
    return classname;
}

From source file:Main.java

public static final void log(String message) {
    StackTraceElement ste = Thread.currentThread().getStackTrace()[3];
    String className = ste.getClassName();
    className = className.substring(className.lastIndexOf(".") + 1);
    String methodName = ste.getMethodName();
    int lineNum = ste.getLineNumber();
    String logText = String.format("%s(%s):%s", methodName, lineNum, message);
    Log.d(className, logText);//from  w  ww.  j a v a  2  s .com
}

From source file:Main.java

public static String getLastPartOfPath(String path) {
    // "/path/path/file/"

    if (path.lastIndexOf('/') == path.length() - 1) {
        path = path.substring(0, path.length() - 1);
    }/*from w  w w  .  j ava  2s  . co  m*/

    // "/path/path/file"

    return path.substring(path.lastIndexOf('/') + 1);

    // "file"
}

From source file:Main.java

private static String getFileNname(String str) {
    String name;// w  w w  . j  ava 2 s .  c o m
    try {
        name = str.substring(str.lastIndexOf("/"), str.lastIndexOf(".")) + ".jpg";
    } catch (Exception e) {
        return null;
    }
    return name;
}

From source file:Main.java

/**
 * Gets the extension of a file./*from  ww  w  .  j  a  va  2s. com*/
 *
 * @param fileName the file name
 * @return the extension of the file.
 */
public static String getExtension(String fileName) {
    String ext = null;
    int i = fileName.lastIndexOf('.');

    if (i > 0 && i < fileName.length() - 1) {
        ext = fileName.substring(i + 1).toLowerCase();
    }
    return ext;
}

From source file:com.shazam.fork.utils.ReadableNames.java

public static String readableClassName(String testClass) {
    final int lastIndexOfDot = testClass.lastIndexOf('.');
    if (lastIndexOfDot != -1) {
        testClass = testClass.substring(lastIndexOfDot + 1);
    }/*from   w ww .  ja  v  a2 s  .com*/
    return testClass;
}