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

/**
 * @return the class name of a proto from its type url. For example, return AesGcmKey
 * if the type url is type.googleapis.com/google.cloud.crypto.tink.AesGcmKey.
 * @throws IllegalArgumentException if {@code typeUrl} is in invalid format.
 *//*from   w w  w.j  av a2  s.  c o  m*/
public static String getProtoClassName(String typeUrl) throws IllegalArgumentException {
    validate(typeUrl);
    int dot = typeUrl.lastIndexOf(".");
    return typeUrl.substring(dot + 1);
}

From source file:Main.java

public static String getFileNameFromPath(String path) {
    if (path == null)
        return "";
    int index = path.lastIndexOf('/');
    if (index > -1)
        return path.substring(index + 1);
    else//from  w  ww.  j  a  v  a 2 s  . c  o  m
        return path;
}

From source file:Main.java

public static final String getFullFileName(String path) {
    String name = null;/*from w w  w . j  a va 2 s . c  o  m*/
    if (path != null) {
        final int index = path.lastIndexOf("/");
        if (index == -1) {
            name = path;
        } else {
            name = path.substring(index + 1);
        }
    }
    return name;
}

From source file:Main.java

/**
 * Returns a multi-line tooltip by wrapping
 * the String input in <html> and inserting breaks <br>.
 * @param len   the maximum line-length.  The method will insert
 * a break at the space closest to this number.
 * @param input   the input String./*from w w w.jav a 2s.com*/
 * @return the new multi-lined string.
 */
public static String multiLineToolTip(int len, String input) {
    String s = "";
    int length = len;
    if (input == null)
        return "";
    if (input.length() < length)
        return input;

    int i = 0;
    int lastSpace = 0;

    while (i + length < input.length()) {
        String temp = input.substring(i, i + length);
        lastSpace = temp.lastIndexOf(" ");
        s += temp.substring(0, lastSpace) + "<br>";
        i += lastSpace + 1;
    }
    s += input.substring(i, input.length());

    s = "<html>" + s + "</html>";

    return s;
}

From source file:Main.java

/**
 * @param s A string representing hours, minutes, seconds, e.g. <code>11:23:44</code>
 * @return The converted number of seconds.
 *///from  w  ww.j ava 2  s .  co  m
public static long fromTimeString(String s) {
    // Handle "00:00:00.000" pattern, drop the milliseconds
    if (s.lastIndexOf(".") != -1)
        s = s.substring(0, s.lastIndexOf("."));
    String[] split = s.split(":");
    if (split.length != 3)
        throw new IllegalArgumentException("Can't parse time string: " + s);
    return (Long.parseLong(split[0]) * 3600) + (Long.parseLong(split[1]) * 60) + (Long.parseLong(split[2]));
}

From source file:Main.java

public static String pathToName(String path) {
    if (TextUtils.isEmpty(path))
        return path;

    int lastSlash = path.lastIndexOf('/');
    if (lastSlash != -1 && lastSlash + 1 < path.length())
        return path.substring(lastSlash + 1);
    else/*from w w  w. j  a v a2 s . c o m*/
        return path;
}

From source file:Main.java

public static String getPackageName(TypeElement classDecl) {
    String fullName = classDecl.getQualifiedName().toString();
    int pos = fullName.lastIndexOf('.');
    if (pos == -1)
        return null;
    return fullName.substring(0, pos);
}

From source file:Main.java

public static String getNameFromPath(String path) {
    if (path == null || path.length() < 2)
        return null;
    int slash = path.lastIndexOf('/');
    if (slash == -1)
        return path;
    else//from   www. j a  va2  s .c om
        return path.substring(slash + 1);
}

From source file:Main.java

/**
 * text of a leaf node, without child element
 * //from  w ww .j a  v a2  s  .  c o  m
 * @param tag
 * @return String
 */
public static String getNodeText(Element tag) {
    String text = tag.toString();
    int i = text.indexOf(">"); //$NON-NLS-1$
    int j = text.lastIndexOf("</"); //$NON-NLS-1$
    if (i < 0 || j < 0 || j < i) {
        return ""; //$NON-NLS-1$
    }

    return text.substring(i + 1, j);
}

From source file:com.teradata.tempto.internal.convention.SqlTestsFileUtils.java

public static String changeExtension(String extension, String fileName) {
    return fileName.substring(0, fileName.lastIndexOf(".")) + '.' + extension;
}