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 hideEmail(String mail) {
    StringBuilder stringBuilder = new StringBuilder();
    if (mail.lastIndexOf("@") > 0) {
        int index = mail.lastIndexOf("@");
        if (index == 1) {
            stringBuilder.append(mail.substring(0, 1));
            stringBuilder.append("***");
            stringBuilder.append(mail.substring(index));
        } else {/*from  w  w w .  j a  v  a2  s. c  o m*/
            stringBuilder.append(mail.substring(0, 1));
            stringBuilder.append("***");
            stringBuilder.append(mail.substring(index - 1));
        }
    } else {
        return mail;
    }
    String mailHidden = stringBuilder.toString();
    if (mailHidden.length() > 20) {
        return mailHidden.substring(0, 20) + "...";
    } else {
        return mailHidden;
    }
}

From source file:Main.java

public static String getFileName(String url) {
    if (TextUtils.isEmpty(url)) {
        return "";
    }/*ww w .j a va2s  .  com*/
    return url.substring(url.lastIndexOf("/") + 1);
}

From source file:Main.java

public static String getClassName() {
    try {/*from  ww  w . j a  v  a 2  s. c o m*/
        String fullClassName = new Exception().getStackTrace()[1].getClassName();
        return fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
    } catch (Exception ex) {
        return "UnknownClass";
    }
}

From source file:Main.java

public static String getMimeType(String url, String defaultType) {
    String extension = "";
    int pos = url.lastIndexOf('.');
    if (pos > 0) {
        extension = url.substring(pos + 1);
    }//from   ww  w. ja v a  2s  .c o  m
    return getMimeTypeFromFileExtension(extension, defaultType);
}

From source file:Main.java

public static String getMimeType(final String fileName) {
    String result = "application/octet-stream";
    int extPos = fileName.lastIndexOf(".");
    if (extPos != -1) {
        String ext = fileName.substring(extPos + 1);
        result = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
    }/*  w w  w  .j ava 2  s .  co  m*/
    return result;
}

From source file:Main.java

public static String getFileName(String path) {
    if (path == null) {
        return null;
    }// w  ww . j ava2s .  c o  m
    int index = -1;
    index = path.lastIndexOf("/");
    return path.substring(index + 1);
}

From source file:com.dangdang.ddframe.rdb.sharding.config.yaml.AbstractYamlShardingDataSourceTest.java

private static String getFileName(final String dataSetFile) {
    String fileName = new File(dataSetFile).getName();
    if (-1 == fileName.lastIndexOf(".")) {
        return fileName;
    }//w w  w.j  a  va2  s  . com
    return fileName.substring(0, fileName.lastIndexOf("."));
}

From source file:Main.java

public static String getFileExtension(String path) {
    if (TextUtils.isEmpty(path)) {
        return null;
    }/*from w  ww. j  a  v  a  2s.  c  o m*/
    int index = path.lastIndexOf(".");
    if (index == -1 || index == path.length() - 1) {
        return null;
    }

    return path.substring(index + 1);
}

From source file:Main.java

/**
 * /*from ww w .  j a v  a2s.  co  m*/
 * @param uri
 * @return
 */
public static String parseNameFromURI(String uri) {

    if (!uri.contains("#")) {
        return uri;
    }

    return uri.substring(uri.lastIndexOf("#") + 1);
}

From source file:Main.java

public static String[] splitFileName(String fileName) {
    String name = fileName;/*  w ww. j a v  a2s.c  o m*/
    String extension = "";
    int i = fileName.lastIndexOf(".");
    if (i != -1) {
        name = fileName.substring(0, i);
        extension = fileName.substring(i);
    }

    return new String[] { name, extension };
}