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 getExtensionName(String filename) {
    if ((filename != null) && (filename.length() > 0)) {
        int dot = filename.lastIndexOf('.');
        if ((dot > -1) && (dot < (filename.length() - 1))) {
            return filename.substring(dot + 1).toLowerCase();
        }//from www  .j a va 2  s  .co m
    }
    return "";
}

From source file:Main.java

private static int getTagEnd(Document doc, int p) {
    int elementEnd = 0;

    if (p > 0) {
        try {//from   w ww . ja v  a  2  s.c o m
            int index = 0;

            String s = doc.getText(0, p);
            int commentStart = s.lastIndexOf("<!--");
            int commentEnd = s.lastIndexOf("-->");

            if (commentStart > 0 && commentStart > commentEnd) {
                index = s.lastIndexOf(">", commentStart);
            } else {
                index = s.lastIndexOf(">");
            }

            if (index != -1) {
                elementEnd = index;
            }
        } catch (BadLocationException bl) {
        }
    }

    return elementEnd;
}

From source file:Main.java

public static String idOfClass(Class<?> clazz) {
    Class<?> theClass = clazz;
    StringBuilder sb = new StringBuilder();
    if (theClass.isArray()) {
        do {/*from   ww w  . jav  a  2  s.c o  m*/
            sb.append("Array"); //$NON-NLS-1$
            theClass = theClass.getComponentType();
        } while (theClass.isArray());
    }
    String clazzName = theClass.getName();
    clazzName = clazzName.substring(clazzName.lastIndexOf('.') + 1);
    return clazzName + sb.toString();
}

From source file:com.liferay.portal.search.elasticsearch.internal.util.ResourceUtil.java

public static File getResourceAsTempFile(Class<?> clazz, String name) throws IOException {

    int index = name.lastIndexOf(CharPool.PERIOD);

    File file = File.createTempFile(name.substring(0, index), name.substring(index));

    file.deleteOnExit();/*w  ww.  j  ava  2 s . co m*/

    try (InputStream inputStream = clazz.getResourceAsStream(name)) {
        FileUtils.copyInputStreamToFile(inputStream, file);
    }

    return file;
}

From source file:Main.java

public static String getExtensionName(String filename) {
    if ((filename != null) && (filename.length() > 0)) {
        int dot = filename.lastIndexOf('.');
        if ((dot > -1) && (dot < (filename.length() - 1))) {
            return filename.substring(dot + 1);
        }//from w w w  .  j a va2s. c  om
    }
    return "";
}

From source file:Main.java

public static String extractNamespaces(String xpath) {
    String result = xpath;// ww w  .  ja v  a2 s.c om
    int ix = xpath.lastIndexOf("declare namespace");
    if (ix != -1) {
        ix = xpath.indexOf('\'', ix + 1);
        if (ix != -1) {
            ix = xpath.indexOf('\'', ix + 1);
            if (ix != -1) {
                ix = xpath.indexOf(';');
                if (ix != -1) {
                    result = xpath.substring(0, ix + 1);
                }
            }
        }
    } else {
        result = "";
    }

    return result;
}

From source file:Main.java

public static String getFileNameNoEx(String filename) {
    if ((filename != null) && (filename.length() > 0)) {
        int dot = filename.lastIndexOf('.');
        if ((dot > -1) && (dot < (filename.length()))) {
            return filename.substring(0, dot);
        }//from   w w w.j  a  v  a  2s .com
    }
    return filename;
}

From source file:Main.java

public static String getParentPath(String path) {
    if (!path.contains(FS)) {
        return FS;
    }//from  ww  w. j  a  va2  s.  c o  m
    if (path.lastIndexOf(FS) < 2) {
        return FS;
    }
    String pass1 = path.substring(0, path.lastIndexOf(FS));
    pass1 = pass1.substring(0, pass1.lastIndexOf(FS));
    Log.i(ID, "getParentPath: " + path + " -> " + pass1);
    return pass1;
}

From source file:Main.java

public static String keepNSecimal(String numberStr, int n) {
    double number = Double.parseDouble(numberStr);
    BigDecimal b = new BigDecimal(number);
    String ss = b.setScale(n, BigDecimal.ROUND_HALF_UP).doubleValue() + "";
    int pointIndex = ss.lastIndexOf(".");
    int fractionCount = ss.length() - pointIndex - 1;
    for (int i = 0; i < n - fractionCount; i++) {
        ss += 0;//  ww w.  j  ava2 s .c  o  m
    }
    return ss;
}

From source file:Main.java

public static String getExtensionName(String filename) {

    if ((filename != null) && (filename.length() > 0)) {
        int dot = filename.lastIndexOf('.');
        if ((dot > -1) && (dot < (filename.length() - 1))) {
            return filename.substring(dot + 1);
        }/*from   w w w.  j ava2 s  .  c om*/
    }
    return filename;
}