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 boolean isGif(String url) {
    if (!TextUtils.isEmpty(url)) {
        int index = url.lastIndexOf("suffix=");
        if (index >= 0 && index + 10 <= url.length()) {
            String type = url.substring(index + 7, index + 10);
            if ("gif".equals(type)) {
                return true;
            }/*from  ww  w. j  a  va 2 s. c om*/
        }
        if (url.contains(".gif")) {
            return true;
        }
        if (url.contains("format=gif")) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static String getFilename(String url) {
    String filename = "";
    int startid = 0;
    int endid = 0;
    startid = url.lastIndexOf("/") + 1;
    endid = url.length();//from   w ww.  java2 s. c om
    filename = url.substring(startid, endid);
    return filename;
}

From source file:Main.java

public static String getThumbnailPath(String src) {
    if (TextUtils.isEmpty(src))
        return null;
    int lastIdx = src.lastIndexOf(".");
    String suffix = src.substring(lastIdx + 1);
    String rest = src.substring(0, lastIdx);
    return rest + ".thumbnail." + suffix;
}

From source file:Main.java

/**
 * Convenience method to extract value from {@code @fooAttribute="blagh"}
 * style filter./*from w w w  . j  a  v a2  s  .c  o  m*/
 *
 * @param filter
 * @return
 */
private static String extractFilterValue(String filter) {
    return filter.substring(filter.indexOf("=\"") + 2, filter.lastIndexOf("\""));
}

From source file:Main.java

public static String[] parseLanguages(File file) {
    String base = file.getName().substring(0, file.getName().indexOf('.'));
    int idx2 = base.lastIndexOf('_');
    int idx1 = base.lastIndexOf('_', idx2 - 1);
    String lng1 = base.substring(idx1 + 1, idx2);
    String lng2 = base.substring(idx2 + 1);
    return new String[] { lng1, lng2 };
}

From source file:Main.java

/**
 * Given an input class object, return a string which consists of the
 * class's package name as a pathname, i.e., all dots ('.') are replaced by
 * slashes ('/'). Neither a leading nor trailing slash is added. The result
 * could be concatenated with a slash and the name of a resource and fed
 * directly to {@code ClassLoader.getResource()}. For it to be fed to
 * {@code Class.getResource} instead, a leading slash would also have
 * to be prepended to the returned value.
 *
 * @param clazz the input class. A {@code null} value or the default
 *              (empty) package will result in an empty string ("") being returned.
 * @return a path which represents the package name
 * @see ClassLoader#getResource//  w w  w  . ja  v a 2s . c  om
 * @see Class#getResource
 */
public static String classPackageAsResourcePath(Class<?> clazz) {
    if (clazz == null) {
        return "";
    }
    String className = clazz.getName();
    int packageEndIndex = className.lastIndexOf(PACKAGE_SEPARATOR);
    if (packageEndIndex == -1) {
        return "";
    }
    String packageName = className.substring(0, packageEndIndex);
    return packageName.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR);
}

From source file:Main.java

public static String getClassSimpleName(final Class<?> clz) {
    final String name = clz.getName();
    final int endCutOff = name.length();
    int beginCutOff = name.lastIndexOf(".") + 1;

    if (beginCutOff == -1)
        beginCutOff = 1;/*w  w  w.  j a  v  a2s  .  co  m*/

    return name.substring(beginCutOff, endCutOff);
}

From source file:Main.java

private static File buildDirectoryHierarchyFor(String entryName, File destDir) {
    int lastIndex = entryName.lastIndexOf('/');
    entryName.substring(lastIndex + 1);//from  w  ww . ja va  2s  . com
    String internalPathToEntry = entryName.substring(0, lastIndex + 1);
    return new File(destDir, internalPathToEntry);
}

From source file:com.hangum.tadpole.commons.utils.zip.util.ZipUtils.java

public static String pack(String fullPath) throws Exception {
    int intlastSep = fullPath.lastIndexOf(File.separator);

    String base_dir = fullPath.substring(0, intlastSep);
    String zipFile = fullPath.substring(intlastSep + 1);

    return pack(base_dir, zipFile);
}

From source file:Main.java

private static String resolveBasePath(final String path) {
    final String name = resolvePath(path);
    return removeExtraSlashes(name.substring(0, name.lastIndexOf('/')));
}