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 getPackageName(Class c) {
    String fullyQualifiedName = c.getName();
    int lastDot = fullyQualifiedName.lastIndexOf('.');
    if (lastDot == -1) {
        return "";
    }//from w  w w .ja  v  a2 s .  c  o m
    return fullyQualifiedName.substring(0, lastDot);
}

From source file:Main.java

private static String dirpart(String name) {
    int s = name.lastIndexOf("/");
    return s == -1 ? null : name.substring(0, s);
}

From source file:Main.java

public static String getFileName(String path) {
    int idx = path.lastIndexOf("/");
    return idx >= 0 ? path.substring(idx + 1) : path;
}

From source file:Main.java

public static String getDirectory(String path) {
    int idx = path.lastIndexOf("/");
    return idx >= 0 ? path.substring(0, idx + 1) : path;
}

From source file:Main.java

public static String getFileNameAndPath(String path) {
    int index = path.lastIndexOf('/');
    return index == -1 || index == (path.length() - 1) ? path : path.substring(index + 1);
}

From source file:Main.java

public static String getFileName(String path) {
    int index = path.lastIndexOf('/');
    return path.substring(index + 1);
}

From source file:Main.java

public static String baseName(String fname) {
    int split = fname.lastIndexOf('/');
    return split == -1 ? fname : fname.substring(split + 1);
}

From source file:Main.java

private static String getTag(String xml) {
    int start = xml.lastIndexOf('/') + 1;
    int end = xml.lastIndexOf('>');
    return xml.substring(start, end);
}

From source file:Main.java

public static String getNewsPicName(String url) {
    int index = url.lastIndexOf("/");
    String name = url.substring(index + 1);
    return name;//from  w  w w.j a  v a  2s  . com
}

From source file:Main.java

public static String getSuffix(String str) {
    int i = str.lastIndexOf('.');
    if (i != -1) {
        return str.substring(i + 1).toUpperCase();
    }// w w  w .ja  va  2s .  c om
    return str;
}