List of usage examples for java.lang String lastIndexOf
public int lastIndexOf(String str)
From source file:Main.java
public static String toTypePart(String fileName) { int point = fileName.lastIndexOf('.'); int length = fileName.length(); return (point == -1 || point == length - 1) ? "" : fileName.substring(point + 1, length); }
From source file:Main.java
/** * Returns the path of the given resource. * * @param uri The URI of the resource/*from w w w . ja v a2s . c o m*/ * @return the resource path */ public static String getPath(String uri) { int i = uri.lastIndexOf('/'); if (i > -1) { return uri.substring(0, i); } i = uri.indexOf(':'); return (i > -1) ? uri.substring(i + 1, uri.length()) : ""; }
From source file:Main.java
public static String getFileDir(String filePath) { return filePath.substring(0, filePath.lastIndexOf(File.separator)); }
From source file:Main.java
/** * Remove index and '-' from layer name. * /* w w w. j av a 2s .c om*/ * @param name * @return */ public static String removeIndex(String name) { int last = name.lastIndexOf("-"); if (name.length() == (last + 1)) { // ends with - not indexed return name; } String indx = name.substring(last + 1); try { // try to parse string after "-" as integer Long.parseLong(indx); // ok, remove index return name.substring(0, last); } catch (Exception ex) { // not valid, not index return name; } }
From source file:Main.java
/** * Get the short name of the given class * /*from w w w.j a v a 2 s . c o m*/ * @param clazz : Class to return the short name for * @return : short name of clazz */ public static String getShortName(Class<?> clazz) { if (clazz == null) { return "null"; } else { String name = clazz.getName(); if (name.lastIndexOf('.') > 0) { name = name.substring(name.lastIndexOf('.') + 1); } return name; } }
From source file:Main.java
public static String getFileName(String name) { String FileName = null;//from w ww . j a va 2 s. c om int dots = name.lastIndexOf('/'); if ((dots > -1) && (dots < (name.length() - 1))) { FileName = name.substring(dots + 1); } return FileName; }
From source file:Main.java
public static boolean isFileUrl(String url) { int lastIndex = url.lastIndexOf("/"); if (lastIndex < url.length() - 1) { return true; }//from www . j ava 2 s .co m return false; }
From source file:Main.java
/** * Gets the sheet name from the cell reference string * * @param ref/*w w w .j av a 2s .c o m*/ * @return the sheet reference */ public static String getSheet(String ref) { int sheetPos = ref.lastIndexOf(sheetInd); if (sheetPos == -1) { return ""; } return ref.substring(0, sheetPos); }
From source file:Main.java
public static String getExtension(String fileName) { int lastDotPosition = fileName.lastIndexOf("."); String ext = fileName.substring(lastDotPosition + 1); ext = ext.replace("_", ""); return ext.trim().toLowerCase(); }
From source file:Main.java
public static String getExtension(String fileName) { int lastDotPosition = fileName.lastIndexOf('.'); String ext = fileName.substring(lastDotPosition + 1); ext = ext.replace("_", ""); return ext.trim().toLowerCase(); }