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

/**
 * Remove the anchor section of a link if present (e.g. for index.html#foo
 * remove #foo)// w ww .j a v  a 2  s  .  c om
 * 
 * @param uri The complete URI e.g. some/path.html#foo
 * 
 * @return the given uri without the anchor if it was found in the uri
 */
public static String stripAnchorIfPresent(String uri) {
    int charPos = uri.lastIndexOf('#');
    if (charPos != -1) {
        return uri.substring(0, charPos);
    } else {
        return uri;
    }
}

From source file:Main.java

/**
 * judge a image format is gif or not//  w ww . j  a v a2  s. c  om
 * 
 * @param imageName
 *            image'name
 * @return true is gif format, false isn't gif format
 */
public static boolean isGifFormatImage(String imageName) {
    String string = imageName.substring(imageName.lastIndexOf(".") + 1);
    if (string.equalsIgnoreCase(IMAGE_TYPT_GIF)) {
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

private static String getUnmappedElementName(Class<?> c, boolean brief) {
    if (brief) {/*from w  w w .ja v  a  2 s . c  o m*/
        String name = c.getName();
        return name.substring(name.lastIndexOf('.') + 1);
    }
    return c.toString();
}

From source file:Main.java

public static String replaceImgSuffix(String imgUrl) {
    String frontPartUrl = imgUrl.substring(0, imgUrl.lastIndexOf(".") + 1);
    String preSuffix = imgUrl.substring(imgUrl.lastIndexOf(".") + 1);
    String hindSuffix = "jpg";
    if (preSuffix.toLowerCase().equals("jpg")) {
        hindSuffix = "png";
    } else if (preSuffix.toLowerCase().equals("png")) {
        hindSuffix = "jpg";
    }/* www . j  a v  a 2  s . c  o m*/
    String newImgUrl = frontPartUrl + hindSuffix;

    return newImgUrl;
}

From source file:Main.java

public static String getInnerCondition(String in) {
    if (in.contains("[")) {
        return in.substring(in.lastIndexOf("=\'") + 2, in.lastIndexOf("'"));

    } else {/*w  w  w. jav  a  2  s .co m*/
        return in.substring(in.lastIndexOf("/") + 1);
    }
}

From source file:Main.java

public static String dirpart(String name) {
    int s = name.lastIndexOf(File.separatorChar);
    return s == -1 ? null : name.substring(0, s);
}

From source file:Main.java

/**
 * Takes the last name of a full XML tag name. If it consists of a generic
 * part and a specific part, then the generic part is removed. examples :
 * "model.infrastructure.node-edge" becomes "edge" : "model.infrastructure'
 * becomes "infrastructure"/*from  w  w  w  .  j a va  2  s . c o  m*/
 *
 * @param fullName The full XML tag name to convert
 * @return The result
 */
public static String getSpecificLastName(String fullName) {
    int beginIndex = Math.max(Math.max(fullName.lastIndexOf('.'), fullName.lastIndexOf('-')), 0) + 1;
    return fullName.substring(beginIndex, fullName.length());
}

From source file:Main.java

public static String getExtension(String name) {
    String ext = null;/*  w  w w .  jav  a2s. com*/
    int i = name.lastIndexOf('.');

    if (i > 0 && i < name.length() - 1) {
        ext = name.substring(i + 1).toLowerCase();
    }

    return ext;
}

From source file:Main.java

private static String getExtension(String filename) {
    String extension = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
    return extension;
}

From source file:Main.java

public static String getActivityName(Context context) {
    String contextString = context.toString();
    return contextString.substring(contextString.lastIndexOf(".") + 1, contextString.indexOf("@"));
}