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

static String stripExtension(String fileName) {
    int index = fileName.lastIndexOf('.');

    // if dot is in the first position,
    // we are dealing with a hidden file rather than an extension
    return (index > 0) ? fileName.substring(0, index) : fileName;
}

From source file:Main.java

protected static int splitIdx(String uriStr) {
    int idx = uriStr.lastIndexOf('#');
    if (idx >= 0)
        return idx;
    // No # - try for /
    idx = uriStr.lastIndexOf('/');
    return idx;/*from   w  w  w  .j  a  v  a2 s. c om*/
}

From source file:Main.java

/**
 * Parse the attribute value for the given id: @+id/object_id from the Android manifest file.
 * @param id the id whose value will be returnd.
 * @return The object_id portion of the string.
 *//*from ww  w .ja v  a  2  s  . c  o m*/
public static String getIdValue(String id) {
    int index = id.lastIndexOf("/"); //$NON-NLS-1$
    if ((index != -1) && ((index + 1) < id.length())) {
        id = id.substring(index + 1);
    }
    return id;
}

From source file:Main.java

public static String getDir(String path) {
    String subString = path.substring(0, path.lastIndexOf('/'));
    return subString.substring(subString.lastIndexOf('/') + 1, subString.length());
}

From source file:Main.java

public static String getDirPath(String filePath) {

    return filePath.substring(0, filePath.lastIndexOf(File.separator));
}

From source file:Main.java

public static String getAltResourcePath(String resourceName, String subdir) {
    int index = resourceName.lastIndexOf('/');

    return resourceName.substring(0, index) + '/' + subdir + resourceName.substring(index);
}

From source file:Main.java

public static int getNewsId(String link) {
    return Integer.parseInt(link.substring(link.lastIndexOf("/") + 1, link.length()).split("\\.")[0]);
}

From source file:Main.java

/**
 * Returns the extension (the substring after the last dot) of the given file. The dot
 * is not included in the returned extension.
 *
 * @param name The filename in question.
 * @return The extension, or an empty string if no extension is found.
 *//*from w w  w. j ava  2s  .  c  om*/
public static String getExtension(String name) {
    int index = name.lastIndexOf('.');
    return index == -1 ? "" : name.substring(index + 1).toLowerCase();
}

From source file:Main.java

public static String fileExt(String url) {
    String ext = url.substring(url.lastIndexOf("."));
    if (ext.indexOf("?") > -1) {
        ext = ext.substring(0, ext.indexOf("?"));
    }//w  w  w  . j  ava2s .c o  m
    if (ext.indexOf("%") > -1) {
        ext = ext.substring(0, ext.indexOf("%"));
    }
    return ext;
}

From source file:Main.java

/**
 * Returns the base name (the substring before the last dot) of the given file. The dot
 * is not included in the returned basename.
 *
 * @param name The filename in question.
 * @return The base name, or an empty string if no basename is found.
 *///  w w w  .  j  ava2s  . c o m
public static String getBaseName(String name) {
    int index = name.lastIndexOf('.');
    return index == -1 ? name : name.substring(0, index);
}