List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:info.mtgdb.api.Db.java
public static ArrayList<Card> getCards(Set<String> fields) { StringBuilder sb = new StringBuilder(); for (String s : fields) { sb.append(s + ","); }/*from ww w .j av a 2 s . c o m*/ if (fields.size() > 0) sb.deleteCharAt(sb.length() - 1); String url = API_URL + "/cards/?fields=" + sb.toString(); return getCardsFromUrl(url); }
From source file:com.vake.ArrayUtils.java
public static String bytesToIpV4Address(byte[] bytes) { final StringBuilder sb = new StringBuilder(); for (byte element : bytes) { final byte[] ipFragmentBytes = new byte[1]; ipFragmentBytes[0] = element;/*from w ww .java 2 s.c om*/ sb.append(bytesToInt(ipFragmentBytes)); sb.append("."); } sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
From source file:com.hemou.android.util.StrUtils.java
public static String arrayToCommaDelimitedString(String[] arr) { StringBuilder sb = new StringBuilder(); if (arr != null) { for (String itm : arr) if (!TextUtils.isEmpty(itm)) sb.append(itm + ","); if (sb.length() == 0) return ""; return sb.deleteCharAt(sb.length() - 1).toString(); } else/* www .j a v a 2 s. co m*/ return ""; }
From source file:com.shenit.commons.utils.CollectionUtils.java
/** * //from w w w. j a va 2s .c o m * @param targets * @param string * @return */ public static <T> String join(T[] targets, String delimiter) { if (ValidationUtils.isEmpty(targets)) return StringUtils.EMPTY; StringBuilder builder = new StringBuilder(); for (T target : targets) { builder.append(target).append(delimiter); } //? if (builder.indexOf(delimiter) > 0) builder.deleteCharAt(builder.lastIndexOf(delimiter)); return builder.toString(); }
From source file:TextUtils.java
/** * Wraps the input string in {@code <html></html>} and breaks it up into * lines with {@code <br>} elements. Useful for making multi-line tootips * and the like./* w ww. j a v a2s . com*/ * * @param s * The input String * @param lineLength * The desired length of the output lines. * @return The HTMLised string */ public static String HTMLiseString(String s, int lineLength) { if (s != null) { StringBuilder buff = new StringBuilder(s); int lineStart = 0; while (lineStart + lineLength < s.length()) { // find the first whitespace after the linelength int firstSpaceIndex = buff.indexOf(" ", lineStart + lineLength); // replace it with a <br> if (firstSpaceIndex != -1) { buff.deleteCharAt(firstSpaceIndex); buff.insert(firstSpaceIndex, "<br>"); lineStart = firstSpaceIndex + 4; } else { lineStart = s.length(); } } buff.insert(0, "<html>"); buff.append("</html>"); return buff.toString(); } return null; }
From source file:com.redhat.rhn.frontend.nav.NavTreeIndex.java
/** * Splits the given url string at the /. Returns the * parts in an array. For example, given "/network/users/details" * this method will return {"/network", "/users", "/details"} * @param urlIn url string to be split.//from ww w. j a va2s .c o m * @return the parts in an array. */ public static String[] splitUrlPrefixes(String urlIn) { String url = StringUtils.strip(urlIn, "/"); String[] splitPath = StringUtils.split(url, "/"); List pathPrefixes = new ArrayList(splitPath.length + 1); // loop through the path parts of URL, creating a new split // URL for each pass, starting with longest, going to shortest for (int i = splitPath.length - 1; i >= 0; i--) { StringBuilder sb = new StringBuilder("/"); for (int j = 0; j <= i; j++) { sb.append(splitPath[j]); sb.append("/"); } // strip off trailing / from last pass in loop sb.deleteCharAt(sb.length() - 1); pathPrefixes.add(sb.toString()); } pathPrefixes.add("/"); return (String[]) pathPrefixes.toArray(new String[] {}); }
From source file:com.whatlookingfor.common.utils.StringUtils.java
/** * ??/*from www.j a va 2 s . c o m*/ * * @param data * @return ?toString */ public static String showByteArray(byte[] data) { if (null == data) { return null; } StringBuilder sb = new StringBuilder("{"); for (byte b : data) { sb.append(b).append(","); } sb.deleteCharAt(sb.length() - 1); sb.append("}"); return sb.toString(); }
From source file:com.graphaware.test.util.TestUtils.java
/** * Execute a set of cypher statements against a database in a single transaction. * * @param serverUrl URL of the database server. * @param cypherStatements to execute.//from w w w . j a v a 2s . com * @return body of the server response. */ public static String executeCypher(String serverUrl, String... cypherStatements) { StringBuilder stringBuilder = new StringBuilder("{\"statements\" : ["); for (String statement : cypherStatements) { stringBuilder.append("{\"statement\" : \"").append(statement).append("\"}").append(","); } stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("]}"); while (serverUrl.endsWith("/")) { serverUrl = serverUrl.substring(0, serverUrl.length() - 1); } return post(serverUrl + "/db/data/transaction/commit", stringBuilder.toString(), HttpStatus.SC_OK); }
From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java
public static String getMacAddr() { try {/*from www . ja v a2s. c o m*/ List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface nif : all) { if (!nif.getName().equalsIgnoreCase("wlan0")) continue; byte[] macBytes = nif.getHardwareAddress(); if (macBytes == null) { return ""; } StringBuilder res1 = new StringBuilder(); for (byte b : macBytes) { res1.append(Integer.toHexString(b & 0xFF) + ":"); } if (res1.length() > 0) { res1.deleteCharAt(res1.length() - 1); } return res1.toString(); } } catch (Exception e) { throw new NfcTagDroidException("can't get mac address", e); } return ""; }
From source file:com.servoy.j2db.server.ngclient.startup.resourceprovider.ComponentResourcesExporter.java
/** * Used in war export to create a components.properties file which is needed to load the components specs in war. * @return the locations of components folders relative to the war dir. *//*from www. ja v a 2 s .c om*/ public static String getComponentDirectoryNames() { StringBuilder locations = new StringBuilder(); Enumeration<String> paths = Activator.getContext().getBundle().getEntryPaths("/war/"); while (paths.hasMoreElements()) { String name = paths.nextElement().replace("war/", ""); if (name.endsWith("/") && !name.equals("js/") && !name.equals("css/") && !name.equals("templates/") && !name.endsWith("services/")) { locations.append("/" + name + ";"); } } locations.deleteCharAt(locations.length() - 1); return locations.toString(); }