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

private static String generateTag() {
    StackTraceElement caller = new Throwable().getStackTrace()[2];
    String tag = "%s.%s(L:%d)";
    String callerClazzName = caller.getClassName();
    callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
    tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber());
    tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag;
    return tag;/*from   w w  w. j a v a 2 s.  co m*/
}

From source file:Main.java

public static String getPathByDeletingPathExtension(String path) {
    if (path == null)
        return null;

    int index = path.lastIndexOf(".");
    if (index == -1)
        return path;

    return path.substring(0, index);
}

From source file:Main.java

/**
 * Gets the extension of a file name, like "png" or "jpg".
 * /*w ww.  ja va 2  s .  c o  m*/
 * @param uri
 * @return Extension excluding the dot("."); "" if there is no extension;
 *         null if uri was null.
 */
public static String getExtension(String uri) {
    if (uri == null) {
        return null;
    }

    int dot = uri.lastIndexOf(".");
    if (dot >= 0) {
        return uri.substring(dot + 1);
    } else {
        // No extension.
        return "";
    }
}

From source file:Main.java

/**
 * Get the simple name of the direct class calling this method.
 *///from ww  w  . jav  a  2  s. c o  m
public static final String getDirectCallingClassSimpleName() {
    final String className = new Exception().getStackTrace()[1].getClassName();
    return className.substring(className.lastIndexOf(".") + 1);
}

From source file:org.osiam.addons.selfadministration.util.RegistrationHelper.java

public static String extractAccessToken(String authorizationHeader) {
    int lastIndexOf = authorizationHeader.lastIndexOf(' ');
    return authorizationHeader.substring(lastIndexOf + 1);
}

From source file:Main.java

public static String getExtension(String name) {
    if (name == null) {
        return "";
    }/*  www  .  ja v  a 2 s  .  com*/
    int index = name.lastIndexOf(".");
    if (index == -1) {
        return "";
    } else {
        return name.substring(index + 1);
    }
}

From source file:Main.java

/**
 * Get the simple name of the indirect class calling this method - the class calling the class
 * calling this method/* ww w  .j  a v  a  2 s .co m*/
 */
public static final String getIndirectCallingClassSimpleName() {
    final String className = new Exception().getStackTrace()[2].getClassName();
    return className.substring(className.lastIndexOf(".") + 1);
}

From source file:Main.java

private static void makeDirs(String fileName) {
    // get the last / or \ position, return if not found
    int lastSlashPos = fileName.lastIndexOf("/");
    if (lastSlashPos == -1) {
        lastSlashPos = fileName.lastIndexOf("\\");

        if (lastSlashPos == -1) {
            return;
        }//from www  . j  av a  2 s  .c  o  m
    }

    String folderPath = fileName.substring(0, lastSlashPos);
    File folderFile = new File(folderPath);
    folderFile.mkdirs();
}

From source file:com.espertech.esper.regression.dataflow.SupportDataFlowAssertionUtil.java

private static void assertException(String expected, String message) {
    String received;/*ww w .  j  a  va  2  s.  c o  m*/
    if (message.lastIndexOf("[") != -1) {
        received = message.substring(0, message.lastIndexOf("[") + 1);
    } else {
        received = message;
    }
    if (message.startsWith(expected)) {
        Assert.assertFalse("empty expected message, received:\n" + message, expected.trim().isEmpty());
        return;
    }
    Assert.fail("Expected:\n" + expected + "\nbut received:\n" + received + "\n");
}

From source file:com.roche.iceboar.downloader.FileUtilsFacade.java

public static String extractFilenameFromURL(String url) {
    if (url.contains("/")) {
        return url.substring(url.lastIndexOf('/') + 1, url.length());
    }/*  www .java2 s.c  o  m*/
    return url;
}