List of usage examples for java.lang String lastIndexOf
public int lastIndexOf(String str)
From source file:Main.java
/** * Remove path and file information from a filename returning only its * extension component/*from w w w. j a v a 2 s. c o m*/ * * @param uri The filename * @return The filename extension (with starting dot!) or null if filename extension is not found */ public static String getExtension(String uri) { int dot = uri.lastIndexOf('.'); if (dot > -1) { uri = uri.substring(dot); int slash = uri.lastIndexOf('/'); if (slash > -1) { return null; } else { int sharp = uri.lastIndexOf('#'); if (sharp > -1) { // uri starts with dot already return uri.substring(0, sharp); } else { int mark = uri.lastIndexOf('?'); if (mark > -1) { // uri starts with dot already return uri.substring(0, mark); } else { return uri; } } } } else { return null; } }
From source file:Main.java
public static void save(String path, Bitmap bitmap) { String name = path.substring(path.lastIndexOf("/")); File file = new File(SAVE_PATH + name); try {//from ww w . j a v a 2s .com if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } FileOutputStream out = new FileOutputStream(file); if (bitmap != null) { bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); } out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static String getPackageFromClassName(final String className) { if (className.contains(".")) { return className.substring(0, className.lastIndexOf('.')); }/*from w ww .j a v a2 s .c om*/ return className; }
From source file:Main.java
public static String oidTail(String id) { if (id == null || !id.contains(".")) return id; return id.substring(id.lastIndexOf(".") + 1); }
From source file:Main.java
public static String getFileType(String fileName) { if (fileName != "" && fileName.length() > 3) { int dot = fileName.lastIndexOf("."); if (dot > 0) { return fileName.substring(dot + 1); } else {/*from w w w . j ava 2 s . c o m*/ return ""; } } return ""; }
From source file:org.obiba.mica.file.FileUtils.java
public static String getParentPath(String path) { int idx = path.lastIndexOf('/'); return idx == 0 ? "/" : path.substring(0, idx); }
From source file:Main.java
private static String getDynamicOptionParentInstanceId(String nodeset) { if (nodeset == null) return null; int pos1 = nodeset.lastIndexOf('/'); if (pos1 < 0) return null; int pos2 = nodeset.lastIndexOf(']'); if (pos2 < 0 || (pos1 == pos2)) return null; return nodeset.substring(pos1 + 1, pos2); }
From source file:Main.java
public static Comparator<String> createFuzzyKeyComparator() { return new Comparator<String>() { @Override//from w w w . ja v a 2s. co m public int compare(String key1, String key2) { String imageUri1 = key1.substring(0, key1.lastIndexOf(URI_AND_SIZE_SEPARATOR)); String imageUri2 = key2.substring(0, key2.lastIndexOf(URI_AND_SIZE_SEPARATOR)); return imageUri1.compareTo(imageUri2); } }; }
From source file:Main.java
static String[] splitFileName(String fileName) { String name = fileName;/* ww w. ja v a 2 s.co m*/ String extension = ""; int i = fileName.lastIndexOf("."); if (i != -1) { name = fileName.substring(0, i); extension = fileName.substring(i); } return new String[] { name, extension }; }
From source file:Main.java
private static String generateTag(StackTraceElement caller) { String tag = "%s.%s(L:%d)"; String callerClazzName = caller.getClassName(); callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1); tag = String.format(tag, callerClazzName, caller.getMethodName(), caller.getLineNumber()); tag = TextUtils.isEmpty(customTagPrefix) ? tag : customTagPrefix + ":" + tag; return tag;/*from w w w . jav a 2s . c om*/ }