List of usage examples for java.lang String lastIndexOf
public int lastIndexOf(String str)
From source file:Main.java
public static String getParentUrl(String url) { int index = url.lastIndexOf("/"); if (index > 0) return url.substring(0, index); return ""; }
From source file:Main.java
/** * Returns the extension of a given filename (excluding the .). If there is * no extension defined, this function returns "". * //w w w. j a v a2 s.co m * @param path * @return */ public static String getExtension(final String path) { final int dotPos = path.lastIndexOf("."); if (dotPos > 0) { return path.substring(dotPos + 1); } return ""; }
From source file:Main.java
public static String getExtension(String uri) { return uri.contains(".") ? uri.substring(uri.lastIndexOf(".") + 1) : ""; }
From source file:Main.java
private static String getVideoContentType(String url) { int dot = url.lastIndexOf("."); String fileType = url.substring(dot + 1); if (fileType.equals("webm")) { return "video/webm"; } else {/*from ww w . j a va 2s .c o m*/ return "video/mp4"; } }
From source file:Main.java
/** * Parse the name of a file to obtain a correct string. * The name is in the format "01 filename.ext" and this method returns "filename" * * @param name String//from w ww .j av a2s. c om * @return String */ public static String parseFileName(String name) { int extension = name.lastIndexOf("."); if (extension > -1) name = name.substring(0, extension); name = name.substring(3).replace("_", "/"); return name; }
From source file:Main.java
public static String GetUpPath(String path) { String retPath = path.substring(0, path.lastIndexOf(File.separator)); return retPath; }
From source file:AudioFilter.java
public static String getExtension(File f) { String ext = null;//w ww . j a va 2s .co m String s = f.getName(); int i = s.lastIndexOf('.'); if (i > 0 && i < s.length() - 1) { ext = s.substring(i + 1).toLowerCase(); } return ext; }
From source file:Main.java
/** * Remove file information from a filename returning only its path component * //from w ww . jav a2 s . co m * @param filename * The filename * @return The path information */ public static String pathComponent(String filename) { int i = filename.lastIndexOf(File.separator); return (i > -1) ? filename.substring(0, i) : filename; }
From source file:Main.java
/** * Returns the path for a file.<br> * <code>path("/home/user/test.jpg") == "/home/user"</code><br> * Uses the correct pathSeparator depending on the operating system. On * windows c:/test/ is not c:\test\/*from www. j av a2 s . c o m*/ * * @param fileName * the name of the file using correct path separators. * @return the path of the file. */ public static String path(final String fileName) { final int sep = fileName.lastIndexOf(File.separatorChar); return fileName.substring(0, sep); }
From source file:Main.java
/** Returns the common ancestor path of s1 and s2 * */ public static int commonPath(String s1, String s2) { int s1c = s1.lastIndexOf(':'); int s2c = s2.lastIndexOf(':'); int i = 0;/*from w w w . j av a2s .co m*/ while (true) { if (i > s1c || i > s2c) break; if (s1.charAt(i) != s2.charAt(i)) break; ++i; } return i; }