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 lastIdentifier(String s) {
    if (s.contains("."))
        return s.substring(s.lastIndexOf(".") + 1);
    else/*w  w  w .  j  ava 2  s  . c om*/
        return s;
}

From source file:Main.java

/**
 * Convenience method for retrieving a subset of the UIDefaults pertaining
 * to a particular class./*from   w  ww.  j a v  a2s  .c  o m*/
 * 
 * @param clazz
 *            the class of interest
 * @return the UIDefaults of the class
 */
public static UIDefaults getUIDefaultsOfClass(final Class clazz) {
    String name = clazz.getName();
    name = name.substring(name.lastIndexOf(".") + 2);
    return getUIDefaultsOfClass(name);
}

From source file:Main.java

public static String getHTTPFileName(String url) {
    if (url == null || url == "")
        return "";
    return url.substring(url.lastIndexOf("/"));
}

From source file:Main.java

/**
 * Get the extension of the file/* w  ww .j a va 2 s. c  om*/
 *
 * @param fileName Name (and location) of the file
 * @return Extension
 */
public static String getFileExtension(String fileName) {
    String extension = "";

    int i = fileName.lastIndexOf('.');
    int p = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));

    if (i > p) {
        extension = fileName.substring(i + 1);
    }

    return extension;
}

From source file:Main.java

/**
 * Apply the given relative path to the given path,
 * assuming standard Java folder separation (i.e. "/" separators).
 * @param path the path to start from (usually a full file path)
 * @param relativePath the relative path to apply
 * (relative to the full file path above)
 * @return the full file path that results from applying the relative path
 *///  w w  w  .java  2  s.  c o  m
public static String applyRelativePath(String path, String relativePath) {
    int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR);
    if (separatorIndex != -1) {
        String newPath = path.substring(0, separatorIndex);
        if (!relativePath.startsWith(FOLDER_SEPARATOR)) {
            newPath += FOLDER_SEPARATOR;
        }
        return newPath + relativePath;
    } else {
        return relativePath;
    }
}

From source file:Main.java

private static String clipPeerIdFromCurrentThreadName() {
    String currName = Thread.currentThread().getName();
    int ix = currName.lastIndexOf(ID_SEPARATOR_IN_THREADNAME);
    if (ix != -1) {
        return currName.substring(ix + 1, currName.length());
    }//from w  w  w.ja  v  a2  s .com
    return "";
}

From source file:Main.java

/**
 * Cleanup title. Remove from title file extension and (...), [...]
 *//*  ww  w  .  j  av a2s. co  m*/
public static String cleanupTitle(final String in) {
    String out = in;
    try {
        out = in.substring(0, in.lastIndexOf('.'));
        out = out.replaceAll("\\(.*?\\)|\\[.*?\\]", "").replaceAll("_", " ").replaceAll(".fb2$", "").trim();
    } catch (final IndexOutOfBoundsException e) {
    }
    return out;
}

From source file:Main.java

public static String splitKeyWord(String data) {
    if (data == null || data.length() == 0)
        return null;
    if (data.lastIndexOf("@") == -1)
        return data;
    return data.substring(0, data.lastIndexOf("@"));
}

From source file:Main.java

public static String[] sepPath(String filePath) {
    if (filePath == null || !filePath.contains("/") || (filePath.lastIndexOf("/") == (filePath.length() - 1))) {
        return null;
    }//from   ww w  . j a  v  a 2  s .c  om
    int index = filePath.lastIndexOf("/") + 1;
    String[] arr = new String[2];
    arr[0] = filePath.substring(0, index);
    arr[1] = filePath.substring(index);
    return arr;
}

From source file:Main.java

/**
 * Unqualify a string qualified by a separator character. For example,
 * "this:name:is:qualified" returns "qualified" if using a ':' separator.
 * @param qualifiedName the qualified name
 * @param separator the separator/*w  w w. j  a v  a  2  s.co  m*/
 */
public static String unqualify(String qualifiedName, char separator) {
    return qualifiedName.substring(qualifiedName.lastIndexOf(separator) + 1);
}