List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:info.schnatterer.nusic.android.util.TextUtil.java
/** * Similar to {@link android.text.Html#fromHtml(String)}, but provides * support for more HTML-tags such as lists. * /*from w w w . ja v a 2 s .c om*/ * @param string * @return */ public static CharSequence fromHtml(String string) { return Html.fromHtml(string.replaceFirst("<title>.*</title>", ""), null, new MyTagHandler()); }
From source file:Main.java
public static String getNodeTextContentFromXmlUrl(String xmlUrl, String nodeWeiZhi) { String result = ""; try {/*w w w . ja va2 s . c o m*/ xmlUrl = xmlUrl.trim(); Element element = getRootNodeFromXmlUrl(xmlUrl); result = getNodeText(element, nodeWeiZhi); } catch (Exception e) { e.printStackTrace(); } return result.replaceFirst(",", ""); }
From source file:Main.java
public static String getNodeTextContentFromXmlStr(String xmlStr, String nodeWeiZhi) { String result = ""; try {/*from w ww . j a v a 2 s .c om*/ xmlStr = xmlStr.trim(); Element element = getRootNodeFromXmlStr(xmlStr); result = getNodeText(element, nodeWeiZhi); } catch (Exception e) { e.printStackTrace(); } return result.replaceFirst(",", ""); }
From source file:com.akamai.edgegrid.signer.EdgeRcClientCredentialProvider.java
/** * Loads an EdgeRc configuration file and returns an {@link EdgeRcClientCredentialProvider} to * read {@link ClientCredential}s from it. * * @param filename a filename pointing to an EdgeRc file * @param section a config section ({@code null} for the default section) * @return a {@link EdgeRcClientCredentialProvider} * @throws ConfigurationException If an error occurs while reading the configuration * @throws IOException if an I/O error occurs *///from w ww . j ava 2 s. c o m public static EdgeRcClientCredentialProvider fromEdgeRc(String filename, String section) throws ConfigurationException, IOException { Validate.notEmpty(filename, "filename cannot be null"); filename = filename.replaceFirst("^~", System.getProperty("user.home")); File file = new File(filename); return fromEdgeRc(new FileReader(file), section); }
From source file:io.github.jeddict.jcode.util.StringHelper.java
/** * Converts `string` to [start case]//from www .ja v a 2s .c o m * * @param content * @return * @example * * startCase('--foo-bar--') => 'Foo Bar' startCase('fooBar') => 'Foo Bar' * startCase('__FOO_BAR__') => 'FOO BAR' */ public static String startCase(String content) { StringBuilder result = new StringBuilder(); content = content.replaceFirst("[^a-zA-Z0-9]+", EMPTY); for (String word : content.replaceAll("[^a-zA-Z0-9]", " ").split(NATURAL_TEXT_SPLITTER)) { result.append(firstUpper(word)).append(" "); } result.setLength(result.length() - 1); return result.toString(); }
From source file:io.github.jeddict.jcode.util.StringHelper.java
/** * Converts `string` to [snake case]//from ww w . j a va 2 s. c o m * * @param content * @return * @example * * Foo Bar > 'foo_bar', fooBar > 'foo_bar', --FOO-BAR-- > 'foo_bar' */ public static String snakeCase(String content) { StringBuilder result = new StringBuilder(); content = content.replaceFirst("[^a-zA-Z0-9]+", EMPTY); for (String word : content.replaceAll("[^a-zA-Z0-9]", " ").split(NATURAL_TEXT_SPLITTER)) { result.append(word.toLowerCase()).append("_"); } result.setLength(result.length() - 1); return result.toString(); }
From source file:io.github.jeddict.jcode.util.StringHelper.java
/** * Converts `string` to [kebab case]//from w w w . ja v a 2s.c o m * * @param content * @return * @example * * 'Foo Bar > 'foo-bar', 'fooBar' > 'foo-bar', '__FOO_BAR__' > 'foo-bar' */ public static String kebabCase(String content) { StringBuilder result = new StringBuilder(); content = content.replaceFirst("[^a-zA-Z0-9]+", EMPTY); for (String word : content.replaceAll("[^a-zA-Z0-9]", " ").split(NATURAL_TEXT_SPLITTER)) { result.append(word.toLowerCase()).append("-"); } result.setLength(result.length() - 1); return result.toString(); }
From source file:com.xebialabs.xlt.ci.server.XLTestServerImpl.java
public static String removeTrailingSlashes(String url) { return url.replaceFirst("/*$", ""); }
From source file:Main.java
private static Uri getUriFromAsset(Context mContext, String path) { File dir = mContext.getExternalCacheDir(); if (dir == null) { Log.e(TAG, "Missing external cache dir"); return Uri.EMPTY; }// w w w.j a va 2 s .c om String resPath = path.replaceFirst("file:/", "www"); String fileName = resPath.substring(resPath.lastIndexOf('/') + 1); String storage = dir.toString() + STORAGE_FOLDER; if (fileName == null || fileName.isEmpty()) { Log.e(TAG, "Filename is missing"); return Uri.EMPTY; } File file = new File(storage, fileName); FileOutputStream outStream = null; InputStream inputStream = null; try { File fileStorage = new File(storage); if (!fileStorage.mkdir()) Log.e(TAG, "Storage directory could not be created: " + storage); AssetManager assets = mContext.getAssets(); outStream = new FileOutputStream(file); inputStream = assets.open(resPath); copyFile(inputStream, outStream); outStream.flush(); outStream.close(); return Uri.fromFile(file); } catch (FileNotFoundException e) { Log.e(TAG, "File not found: assets/" + resPath); } catch (IOException ioe) { Log.e(TAG, "IOException occured"); } catch (SecurityException secEx) { Log.e(TAG, "SecurityException: directory creation denied"); } finally { try { if (inputStream != null) { inputStream.close(); } if (outStream != null) { outStream.flush(); outStream.close(); } } catch (IOException ioe) { Log.e(TAG, "IOException occured while closing/flushing streams"); } } return Uri.EMPTY; }
From source file:Main.java
/** * Remove the XPath special characters./*ww w. ja v a 2 s . c o m*/ * * @param input * - the return value of XPath. * @return a String that doesn't contain any XPath characters. * @throws IllegalArgumentException * if the input string is empty or null or equals [] (an empty * mods tag). */ public static String removeCtrlChars(final String input) { if (input == null || input.length() == 0 || input.equals("[]")) { throw new IllegalArgumentException( "The value for the parameter input in removeCtrlChars mustn't be empty."); } // Ex. value: [] String ret = input.replaceFirst("[\\[]+(\\w)+: ((\\w)+=\")?", ""); int lastPos = input.lastIndexOf("]"); if (lastPos == input.length() - 1) { ret = ret.substring(0, ret.length() - 1); if (ret.length() > 1 && ret.lastIndexOf("\"]") == ret.length() - 2) { ret = ret.substring(0, ret.length() - 2); } } return ret; // return input; }