List of usage examples for java.lang String lastIndexOf
public int lastIndexOf(String str)
From source file:Main.java
private static String updateFormat(String dateTime) { if (dateTime.indexOf('y') == dateTime.lastIndexOf('y')) { dateTime = dateTime.replace("y", "yyyy"); }/*ww w. j a v a2s . c o m*/ return dateTime; }
From source file:Main.java
public static String stripExtension(String inputString) { int lastIndex = inputString.lastIndexOf("."); if (lastIndex < 0) { return inputString; }//from w ww. j av a 2 s . c om int fileSeparatorLastIndex = inputString.lastIndexOf(File.separator); if (fileSeparatorLastIndex < 0 && lastIndex == 0) { return inputString; } if (fileSeparatorLastIndex >= 0 && fileSeparatorLastIndex > lastIndex) { return inputString; } return inputString.substring(0, lastIndex); }
From source file:Main.java
public static String getName(Object obj) { String name = obj.getClass().getName(); int dotPos = name.lastIndexOf("."); if (dotPos != -1 && dotPos < name.length() - 1) { return name.substring(dotPos + 1); } else {/*from ww w . j a va 2 s .c o m*/ return name; } }
From source file:Main.java
public static String removePrefix(final String qName) { String localName = qName; int index = localName.lastIndexOf(":"); if (index != -1) { localName = localName.substring(index + 1); }//from www . j av a2s. c om return localName; }
From source file:Main.java
public static String getFolder(String s) { String path = new File(s).getParent(); return path.substring(path.lastIndexOf("/") + 1); }
From source file:Main.java
/** * <p>Determines the parent directory of the given path. This is similar to * dirname(1). This assumes that path components are separated by forward * slashes.</p>//from www. java 2 s. c o m * * <p>The returned path omits the last slash and trailing component; * for example, "/foo/bar.txt" becomes "/foo". There are a special cases: * <ul> * <li> If the last slash is the first character in the input, * the return value is "/". * <li> If there are no slashes in the input, "." is returned. * </ul> * </p> * * @param path the path to strip * @return the parent path, as described above */ public static String dirname(String path) { int lastSlash = path.lastIndexOf("/"); if ("/".equals(path) || lastSlash == 0) { return "/"; } else if (lastSlash == -1) { return "."; } else { return path.substring(0, lastSlash); } }
From source file:Main.java
public static String getFilteredFolderName(String display_name) { display_name = display_name.substring(display_name.lastIndexOf("/") + 1); display_name = display_name.substring(display_name.lastIndexOf(".") + 1); return display_name; }
From source file:Main.java
public static String getPackageName(Class<?> clazz) { String className = clazz.getName(); int lastIndex = className.lastIndexOf("."); if (lastIndex != -1) { return className.substring(0, lastIndex); } else {/*w w w .j av a2 s. c o m*/ return null; } }
From source file:Main.java
public static String getFileType(File file) { String fileName = file.getName(); int typeIndex = fileName.lastIndexOf("."); if (typeIndex != -1) { return fileName.substring(typeIndex + 1).toLowerCase(); } else {//from ww w .jav a 2 s .c o m return ""; } }
From source file:Main.java
public static String extractFilterCriteria(String selectedCriteria) { return (selectedCriteria.substring(0, selectedCriteria.lastIndexOf("("))).trim(); }