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, int fromIndex) 

Source Link

Document

Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.

Usage

From source file:Main.java

public static void main(String args[]) {
    String s = "this is a test from java2s.com.";

    System.out.println(s);/*from   w  w w .  j  ava  2 s. c  om*/
    System.out.println("lastIndexOf(t, 60) = " + s.lastIndexOf('t', 60));

}

From source file:Main.java

public static void main(String args[]) {
    String s = "this is a test from java2s.com.";

    System.out.println(s);/*  w w w  .j a va  2 s  . c  o m*/
    System.out.println("lastIndexOf(the, 60) = " + s.lastIndexOf("the", 60));

}

From source file:MainClass.java

public static void main(String args[]) {
    String s = "public static void main(String args[]) {";
    System.out.println(s);/*w  w  w . j a  v  a2s.  c om*/
    System.out.println("lastIndexOf(t, 50) = " + s.lastIndexOf('t', 50));
}

From source file:MainClass.java

public static void main(String args[]) {
    String s = "public static void main(String args[]) {";
    System.out.println(s);// ww w. j  a v  a2s.  co m
    System.out.println("lastIndexOf(the, 50) = " + s.lastIndexOf("the", 50));
}

From source file:Main.java

/**
 * judge whether is a pdf file.//from   w  w  w .  j  a v  a 2s  . c o  m
 * 
 * @param path the file path
 * @return true if it is a image file, otherwise false
 */
public static boolean isPdfFile(String path) {

    String extention = path.substring(path.lastIndexOf(".", path.length()) + 1, path.length());
    if (extention.equalsIgnoreCase("pdf")) {
        return true;
    }
    return false;
}

From source file:Main.java

/**
 * judge whether is a pdz file.//from  w ww.  j a v  a 2 s  . c o m
 * 
 * @param path the file path
 * @return true if it is a image file, otherwise false
 */
public static boolean isTemplateFile(String path) {

    String extention = path.substring(path.lastIndexOf(".", path.length()) + 1, path.length());
    if (extention.equalsIgnoreCase("pdz") || extention.equalsIgnoreCase("blf")) {
        return true;
    }
    return false;
}

From source file:Main.java

public static int toPathLsatIndex(String fileName, int fromIndex) {
    int point = fileName.lastIndexOf('/', fromIndex);
    if (point == -1) {
        point = fileName.lastIndexOf('\\', fromIndex);
    }/*from   w  w  w .  ja  v  a 2  s .  com*/
    return point;
}

From source file:net.sf.zekr.common.util.StringUtils.java

/**
 * Similar to {@link org.apache.commons.lang.StringUtils#abbreviate(String, int)} method but adds no
 * ellipsis to the end of the abbreviated string. This method also abbreviates to the nearest space
 * character (\x20), so that the result string size is smaller or equal to size parameter.<br>
 * This method returns an empty string if no space character found within the given size range.
 * // ww  w .  j av  a  2s .com
 * @param str string to be abbreviated
 * @param size boundary to which the result size of abbreviated string is less or equal
 * @return abbreviated string
 */
public static String abbreviate(String str, int size) {
    if (str.length() <= size)
        return str;
    int index = str.lastIndexOf(' ', size);
    if (index <= -1)
        return "";
    return str.substring(0, index);
}