List of usage examples for java.lang String lastIndexOf
public int lastIndexOf(String str)
From source file:Main.java
public static String getFileName(String path) { if (path != null && !"".equals(path)) { return path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).trim(); }//from w w w . java2 s . c o m return ""; }
From source file:Main.java
/** * Mimetype String of a file//from w w w .j a va2 s .c om * @param path * @return */ public static String getMimeTypeFromName(String path) { String extension = ""; int pos = path.lastIndexOf('.'); if (pos >= 0) { extension = path.substring(pos + 1); } String result = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase()); return (result != null) ? result : ""; }
From source file:Main.java
/** * @brief get base url from a web full address * //from www . ja va 2s .c o m * @param url [IN] web full address * * @return Return base url */ public static String getBaseUrl(String url) { if (url != null) { String baseURL = url.substring(0, url.lastIndexOf("/") + 1); return baseURL; } return null; }
From source file:Main.java
/** * Given an input class object, return a string which consists of the class's package name as a pathname, i.e., all dots ('.') are replaced by slashes ('/'). Neither a leading nor trailing slash is added. The result could be concatenated with a slash and the name of a resource, and fed directly to <code>ClassLoader.getResource()</code>. For it to be fed to <code>Class.getResource</code> instead, a leading slash would also have to be prepended to the returned value. * //from www . j a v a 2 s .c o m * @param clazz * the input class. A <code>null</code> value or the default (empty) package will result in an empty string ("") being returned. * @return a path which represents the package name * @see ClassLoader#getResource * @see Class#getResource */ public static String classPackageAsResourcePath(Class<?> clazz) { if (clazz == null) { return ""; } String className = clazz.getName(); int packageEndIndex = className.lastIndexOf('.'); if (packageEndIndex == -1) { return ""; } String packageName = className.substring(0, packageEndIndex); return packageName.replace('.', '/'); }
From source file:Main.java
public static String typename(Class t) { String brackets = ""; while (t.isArray()) { brackets += "[]"; t = t.getComponentType();/*from w w w.j a va2s . com*/ } String name = t.getName(); int pos = name.lastIndexOf('.'); if (pos != -1) name = name.substring(pos + 1); return name + brackets; }
From source file:Main.java
private static String getPrefix(Set<String> names) { if (names.isEmpty()) { return ""; }//w ww . jav a 2s. c om String name = (String) names.toArray()[0]; return name.substring(0, name.lastIndexOf("_")); }
From source file:Main.java
public static String getName(String file) { if (file != null && !"".equals(file)) { int index = file.lastIndexOf("/"); if (index != -1) { return file.substring(index + 1); } else {/*w w w . ja va2 s.c o m*/ return ""; } } return null; }
From source file:Main.java
public static String genrateName(String url) { String result = ""; try {/*from w ww.j a v a 2 s. com*/ result = url.substring(url.lastIndexOf('/') + 1); } catch (Exception e) { } return result; }
From source file:Main.java
public static String generateBlurryThumbnailUrl(String imageUrl, int width, int height, int blur) { if (imageUrl == null) { return null; }//w ww .j ava 2s .com int i = imageUrl.indexOf("upload/"); if (i > 0) { i += 7; String blurryImageUrl = imageUrl.substring(0, i); blurryImageUrl += "w_" + width + ",h_" + height + ",c_limit,e_blur:" + blur + "/"; String file = imageUrl.substring(i); i = file.lastIndexOf('.'); if (i > 0) { file = file.substring(0, i); } return blurryImageUrl + file + ".jpg"; } return imageUrl; }
From source file:Utils.java
/** * Returns the name of a class without the package name. For example: if * input = "java.lang.Object" , then output = "Object". * @param fully qualified classname/*w ww .j a v a 2 s.c o m*/ * @return the unqualified classname */ public static String getShortClassName(final String className) { if (className != null) { final int index = className.lastIndexOf('.'); return className.substring(index + 1); } return null; }