List of usage examples for java.lang StringBuffer lastIndexOf
@Override public int lastIndexOf(String str)
From source file:Main.java
public static void main(String[] arg) { StringBuffer phrase = new StringBuffer("java2s.com"); int position = phrase.lastIndexOf(".com"); System.out.println(position); }
From source file:MainClass.java
public static void main(String[] arg) { StringBuffer phrase = new StringBuffer("one two three four"); int position = phrase.lastIndexOf("three"); System.out.println(position); }
From source file:MainClass.java
public static void main(String[] arg) { StringBuffer phrase = new StringBuffer("one two three four"); String substring = "two"; String replacement = "twenty"; int position = phrase.lastIndexOf(substring); // Find start of "two" phrase.replace(position, position + substring.length(), replacement); System.out.println(phrase);/*from w w w.j av a 2s. c om*/ }
From source file:IndexOfDemo.java
public static void main(String args[]) { StringBuffer sb = new StringBuffer("one two one"); int i;/*from ww w.j av a2 s . c o m*/ i = sb.indexOf("one"); System.out.println("First index: " + i); i = sb.lastIndexOf("one"); System.out.println("Last index: " + i); }
From source file:gov.nyc.doitt.gis.geoclient.parser.regex.PatternUtils.java
public static String literalMatchGroup(Collection<String> strings) { Assert.notEmpty(strings, "Collection of strings argument cannot be empty or null"); StringBuffer buff = new StringBuffer("("); for (String s : strings) { buff.append(s);//from w w w . j a v a 2 s . c om buff.append("|"); } buff.deleteCharAt(buff.lastIndexOf("|")); buff.append(")"); return buff.toString(); }
From source file:Main.java
/** * returns a string where each object in the give {@code Collection} is placed on a new line * (i.e [foo, bar, bizz] -> <br/> foo <br/> bar <br/> bizz) * @param collection a given {@code Collection} of type {@code T} * @return/*from ww w. j av a2 s . c o m*/ */ public static <T> String lineSeparatedCollection(Collection<T> collection) { StringBuffer sb = new StringBuffer(""); for (T item : collection) { sb.append(item.toString()).append(LINE_SEPARATOR); } return sb.deleteCharAt(sb.lastIndexOf(LINE_SEPARATOR)).toString(); }
From source file:Main.java
/** * returns a string where each object in the give {@code Collection} is placed on a new line * (i.e [foo, bar, bizz] -> <br/> foo <br/> bar <br/> bizz) * @param collection a given {@code Array} of type {@code T} * @return/*from w w w .j a v a2 s . com*/ */ public static <T> String lineSeparatedCollection(T... collection) { StringBuffer sb = new StringBuffer(""); for (T item : collection) { sb.append(item.toString()).append(LINE_SEPARATOR); } return sb.deleteCharAt(sb.lastIndexOf(LINE_SEPARATOR)).toString(); }
From source file:org.eclipse.rap.rwt.supplemental.fileupload.internal.FileUploadServiceHandler.java
public static String getUrl(String token) { ServiceManager manager = RWT.getServiceManager(); String rootURL = manager.getServiceHandlerUrl(SERVICE_HANDLER_ID); StringBuffer url = new StringBuffer(); url.append(rootURL);// w w w . j a v a 2 s .c o m url.append("&"); //$NON-NLS-1$ url.append(PARAMETER_TOKEN).append("=").append(token); //$NON-NLS-1$ int relativeIndex = url.lastIndexOf("/"); //$NON-NLS-1$ if (relativeIndex > -1) { url.delete(0, relativeIndex + 1); } return RWT.getResponse().encodeURL(url.toString()); }
From source file:Main.java
public static String getVerticalText(String text) { StringBuffer stringBuffer = new StringBuffer(); if (text != null && text.length() > 0) { int length = text.length(); for (int i = 0; i < length; i++) stringBuffer.append(text.charAt(i) + "\n"); }//from w w w . j a v a 2s. c o m stringBuffer.deleteCharAt(stringBuffer.lastIndexOf("\n")); return stringBuffer.toString(); }
From source file:org.eclipse.dirigible.ide.workspace.dual.DownloadProjectServiceHandler.java
/** * Generator for the download URL// w w w.j a v a 2 s.c om * * @param token * @return the URL */ public static String getUrl(String token) { ServiceManager manager = RWT.getServiceManager(); String rootURL = manager.getServiceHandlerUrl(SERVICE_HANDLER_ID); StringBuffer url = new StringBuffer(); url.append(rootURL); url.append(AMP); url.append(FILENAME_PARAM).append(EQ).append(token).append(ZIP); int relativeIndex = url.lastIndexOf(SLASH); if (relativeIndex > -1) { url.delete(0, relativeIndex + 1); } return RWT.getResponse().encodeURL(url.toString()); }