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 getSuffix(String fileName) {
    if (fileName == null)
        return null;
    int point = fileName.lastIndexOf(".");
    if (point != -1) {
        return fileName.substring(point + 1);
    }/*  w w  w .  j  a v a 2  s  .co m*/
    return fileName;
}

From source file:Main.java

public static String getFormat(String url) {
    String extension = "";
    if (url.length() > 0) {
        int dot = url.lastIndexOf('.');
        if ((dot > -1) && (dot < (url.length() - 1))) {
            extension = url.substring(dot);
        }//from  www. ja v  a  2 s . c  o m
    }
    return extension;
}

From source file:Main.java

private static String getType(String path) {

    String type;//from   w  ww .ja va  2s.c om
    type = "";
    try {
        int pos = path.lastIndexOf(".");
        if (pos != -1) {
            type = path.substring(pos + 1);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return type;
}

From source file:Main.java

public static String getFileNameFromPath(String filepath) {
    if ((filepath != null) && (filepath.length() > 0)) {
        int sep = filepath.lastIndexOf('/');
        if ((sep > -1) && (sep < filepath.length() - 1)) {
            return filepath.substring(sep + 1);
        }//from   ww w.j ava 2 s .  c  o m
    }
    return filepath;
}

From source file:Main.java

public static String getFileNameFromPath(String path) {
    if (path == null) {
        return "";
    }/*from w ww.ja va2s .  co  m*/
    int index = path.lastIndexOf('/');
    return index > -1 ? path.substring(index + 1) : path;
}

From source file:Main.java

/**
 * Compute the local name of a qualified name. NOTE : this also works if qName is a path, eg
 * "./office:body/office:text" or if there's no prefix, eg "./office:body/child".
 * /*from   www  .  j av  a  2s.c o  m*/
 * @param qName a qualified name, eg "office:text".
 * @return the local name, eg "text".
 */
public final static String localName(String qName) {
    qName = basename(qName);
    return qName.substring(qName.lastIndexOf(':') + 1);
}

From source file:Main.java

public static String getMIMEType(String file) {
    String type = "";
    String end = file.substring(file.lastIndexOf(".") + 1, file.length()).toLowerCase();
    if (end.equals("apk")) {
        return "application/vnd.android.package-archive";
    } else if (end.equals("mp4") || end.equals("avi") || end.equals("3gp") || end.equals("rmvb")) {
        type = "video";
    } else if (end.equals("m4a") || end.equals("mp3") || end.equals("mid") || end.equals("xmf")
            || end.equals("ogg") || end.equals("wav")) {
        type = "audio";
    } else if (end.equals("jpg") || end.equals("gif") || end.equals("png") || end.equals("jpeg")
            || end.equals("bmp")) {
        type = "image";
    } else if (end.equals("txt") || end.equals("log")) {
        type = "text";
    } else {/*  ww w .j  av a  2 s  .  com*/
        type = "*";
    }
    type += "/*";
    return type;
}

From source file:Main.java

public static String getFileName(String path) {
    if (path != null && !"".equals(path.trim())) {
        return path.substring(path.lastIndexOf("/"));
    }/*from   w ww.  jav a 2 s . c o  m*/

    return "";
}

From source file:com.machinelinking.util.FileUtil.java

public static String getExtension(String path) {
    final int extIndex = path.lastIndexOf(".");
    return extIndex != -1 ? path.substring(extIndex + 1) : null;
}

From source file:Main.java

/**
 * function to get homeTeam or awayTeam id from Team href link
 *
 * @param crestUrl crestUrl of team//from   w  ww.  j  a  va 2 s.  c  om
 * @return String modified logo url path for .png image
 */
public static String getTeamLogo(String crestUrl) {
    String svgLogoUrl = crestUrl;
    String filename = svgLogoUrl.substring(svgLogoUrl.lastIndexOf("/") + 1);
    int wikipediaPathEndPos = svgLogoUrl.indexOf("/wikipedia/") + 11;
    String afterWikipediaPath = svgLogoUrl.substring(wikipediaPathEndPos);
    int insertPos = wikipediaPathEndPos + afterWikipediaPath.indexOf("/") + 1;
    String afterLanguageCodePath = svgLogoUrl.substring(insertPos);
    crestUrl = svgLogoUrl.substring(0, insertPos);
    crestUrl += "thumb/" + afterLanguageCodePath;
    crestUrl += "/200px-" + filename + ".png";
    return crestUrl;
}