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 getSimpleClassName(String className) {
    int lastIndex = className.lastIndexOf(".");
    int index = lastIndex + 1;
    if (lastIndex > 0 && index < className.length()) {
        return className.substring(index);
    }//www. j av a2s . co m
    return className;
}

From source file:Main.java

public static String getFileExtension(File file) {
    String name = file.getName();
    int lastIndexOf = name.lastIndexOf(".");
    if (lastIndexOf == -1) {
        return ""; // empty extension
    }//w  ww  .  j  a v a2  s .  c  o m
    return name.substring(lastIndexOf);
}

From source file:Main.java

public static String getName(String url) {
    String a = url.substring(0, url.lastIndexOf("/"));

    return a.substring(a.lastIndexOf("/") + 1) + ".jpg";
}

From source file:Main.java

public static String strRightBack(String input, String delimiter) {
    return input.substring(input.lastIndexOf(delimiter) + delimiter.length());
}

From source file:Main.java

public static String substringAfterLast(String string, String delimiter) {
    final int index = string.lastIndexOf(delimiter);
    if (index == -1 || string.endsWith(delimiter)) {
        return "";
    }//from   w  w w  .java 2 s.c  o m
    return string.substring(index + 1);
}

From source file:Main.java

public static String GetQValue(String sp) {

    {//from   ww  w  .  j  ava 2  s .c o  m
        return ((sp).substring(0, sp.lastIndexOf("+"))).trim();
    }

}

From source file:Main.java

public static String getResourceURL(String sxURL, String resource) {
    return sxURL.substring(0, sxURL.lastIndexOf("/")) + resource;
}

From source file:Main.java

public static String getDownAudioPath(Context context, String url) {
    String fileName = url.substring(url.lastIndexOf("/") + 1);
    File mediaStorageDir = new File(context.getExternalFilesDir(Environment.DIRECTORY_RINGTONES),
            AudioFolderName);/*ww  w.  j  ava2 s.  co m*/

    return mediaStorageDir.getPath() + File.separator + fileName;
}

From source file:Main.java

private static String extractMapName(String root) {
    int indexOfSlash = root.lastIndexOf('/');

    if (indexOfSlash != -1) {

        return root.substring(indexOfSlash + 1);
    }//from   ww  w. ja  v  a2  s.  co  m

    return root;
}

From source file:Main.java

/**
 * http://36kr.com/p/5040401.html-->5040401
 * @param pStr/*from w ww.  j a  va 2 s  .  com*/
 * @return
 */
public static String getArticleId(String pStr) {
    String tempStr = pStr.substring(pStr.lastIndexOf("/") + 1);
    if (tempStr.contains(".")) {
        String[] temp = tempStr.split("\\."); //  5040196
        return temp[0];
    }
    return pStr;
}