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

/**
 * Gets the final component from a path.  This assumes that path components
 * are separated by forward slashes./* www  .  ja  v a 2  s.  c  o  m*/
 *
 * @param path The path to apply the basename operation to.
 * @return path, with any leading directory elements removed
 */
public static String basename(String path) {
    if (path.length() == 0) {
        return path;
    }

    int pos = path.lastIndexOf("/");
    if (pos == -1) {
        return path;
    } else {
        return path.substring(pos + 1);
    }
}

From source file:Main.java

private static String generateVerboseTag(StackTraceElement caller) {
    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;//  w  w  w . j a va2  s  . c om
}

From source file:Main.java

public static String getFileExtenSion(File file) {
    String ex;//from  w ww. ja v  a2 s  . c o  m
    String filename;
    try {
        filename = file.getName();
        ex = filename.substring(filename.lastIndexOf(".") + 1);

    } catch (Exception e) {
        return "";
    }
    return ex.toLowerCase(Locale.getDefault());
}

From source file:Main.java

private static String generateTag(StackTraceElement caller) {
    String tag = "%s.%s(Line:%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;/*  www .  j  a  va  2 s.  co m*/
}

From source file:Main.java

public static String getFolderPath(String path) {
    String folderPath = "";

    if (!TextUtils.isEmpty(path)) {
        int i = path.lastIndexOf('/');
        if (i > 0) {
            folderPath = path.substring(0, i);
        }//from   w w  w.  j a v  a2 s  . c  o m
    }

    return folderPath;
}

From source file:Main.java

public static String getExternalPackageId(String extPkgHref) {
    //      System.out.println("EPID1="+extPkgHref);
    int indBSL = extPkgHref.lastIndexOf("\\");
    int indSL = extPkgHref.lastIndexOf("/");
    int indDotXPDL = extPkgHref.lastIndexOf(".xpdl");
    if (indSL != -1 || indBSL != -1) {
        int ind = indSL;
        if (indBSL > indSL) {
            ind = indBSL;//from w ww .j a  v a2  s  .c  o m
        }
        extPkgHref = extPkgHref.substring(indSL + 1);
    }
    if (indDotXPDL != -1) {
        extPkgHref = extPkgHref.substring(0, extPkgHref.length() - 5);
    }
    //      System.out.println("EPID2="+extPkgHref);
    return extPkgHref;
}

From source file:Main.java

public static int indexOfLastSeparator(String filePath) {
    if (filePath == null) {
        return -1;
    }//from   w  w w.j  ava  2  s.  co m
    int lastUnixPos = filePath.lastIndexOf(UNIX_SEPARATOR);
    int lastWindowsPos = filePath.lastIndexOf(WINDOWS_SEPARATOR);
    return (lastUnixPos >= lastWindowsPos) ? lastUnixPos : lastWindowsPos;
}

From source file:com.intuit.karate.JsonUtils.java

public static Pair<String, String> getParentAndLeafPath(String path) {
    int pos = path.lastIndexOf('.');
    String left = path.substring(0, pos == -1 ? 0 : pos);
    String right = path.substring(pos + 1);
    return Pair.of(left, right);
}

From source file:Main.java

public static JSONObject convertStringToJSON(String jsonString) throws JSONException {
    String secureJSONString = jsonString.substring(jsonString.indexOf("{"), jsonString.lastIndexOf("}") + 1);
    JSONObject jsonObject = new JSONObject(secureJSONString);
    return jsonObject;
}

From source file:me.yanaga.winter.data.jpa.spring.config.metadata.EnableRepositoriesMetadata.java

private static String obtainPackageName(String className) {
    int lastIndexOf = className.lastIndexOf('.');
    return lastIndexOf != -1 ? className.substring(0, lastIndexOf) : "";
}