List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:com.autentia.common.util.StringUtils.java
public static String trimBrackets(String stringToTrim) { final StringBuilder result = new StringBuilder(stringToTrim); while (result.toString().startsWith("[")) { result.deleteCharAt(0); }/*w w w.j ava2 s .co m*/ while (result.toString().endsWith("]")) { result.deleteCharAt(result.length() - 1); } return result.toString(); }
From source file:Main.java
public static String toString(String[] permission) { if (permission == null || permission.length <= 0) { return ""; }//ww w . j av a 2s. c om StringBuilder sb = new StringBuilder(); for (String p : permission) { sb.append(p.replaceFirst("android.permission.", "")); sb.append(","); } sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
From source file:Main.java
/** * Trim <i>all</i> whitespace from the given String: * leading, trailing, and in between characters. * @param str the String to check//from w w w . j a v a 2s .c o m * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimAllWhitespace(String str) { if (!hasLength(str)) { return str; } StringBuilder sb = new StringBuilder(str); int index = 0; while (sb.length() > index) { if (Character.isWhitespace(sb.charAt(index))) { sb.deleteCharAt(index); } else { index++; } } return sb.toString(); }
From source file:Main.java
public static <T> String listToString(List<T> list) { if (null == list || list.isEmpty()) { return ""; }/*from w w w . ja v a 2s. c om*/ StringBuilder sb = new StringBuilder(); for (T i : list) { sb.append(i.toString()); sb.append(","); } int index = sb.lastIndexOf(","); if (-1 != index) { sb.deleteCharAt(index); } return sb.toString(); }
From source file:com.github.jknack.amd4j.ResourceURI.java
/** * Creates a {@link ResourceURI}.//from w w w . j ava 2 s.c om * * @param baseUrl The base url. * @param path The dependency's path. It might be prefixed with: <code>prefix!</code> where * <code>prefix</code> is usually a plugin. * @return A new {@link ResourceURI}. */ public static ResourceURI create(final String baseUrl, final String path) { notEmpty(baseUrl, "The baseUrl is required."); String normBaseUrl = baseUrl; if (".".equals(normBaseUrl)) { normBaseUrl = SEPARATOR; } if (!normBaseUrl.startsWith(SEPARATOR)) { normBaseUrl = SEPARATOR + normBaseUrl; } if (!normBaseUrl.endsWith(SEPARATOR)) { normBaseUrl += SEPARATOR; } int idx = Math.max(0, path.indexOf('!') + 1); StringBuilder uri = new StringBuilder(path); if (uri.charAt(idx) == SEPARATOR.charAt(0)) { uri.deleteCharAt(idx); } uri.insert(idx, normBaseUrl); return create(uri.toString()); }
From source file:com.fluidinfo.utils.StringUtil.java
/** * Joins an array of strings with the specified delimiter * @param s The strings to join/* w ww. jav a 2s. c o m*/ * @param delim The delimiter * @return The joined strings */ public static String join(String[] s, String delim) { if (s == null || s.length == 0) return ""; StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length; i++) { sb.append(s[i]).append(delim); } return sb.deleteCharAt(sb.length() - 1).toString(); }
From source file:com.conwet.xjsp.json.JSONUtil.java
public static void discardSpaces(StringBuilder buffer) { while (buffer.length() > 0 && (isSpace(buffer.charAt(0)) || buffer.charAt(0) == ',')) { buffer.deleteCharAt(0); }//from w ww . ja v a 2s. c o m }
From source file:Main.java
@Deprecated public static String toHexString(byte[] content, int len) { if (content == null || content.length == 0) { return ""; }//www. j av a 2 s. c o m if (len > content.length) { len = content.length; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { int c = content[i]; c &= 0xFF; sb.append(' ').append(HEXS[c / 16]).append(HEXS[c % 16]); } sb.deleteCharAt(0); return sb.toString(); }
From source file:Main.java
/** * Removes the first occurrence of the given character from the string * @param c - character to remove (first occurrence) * @param str- string to search//from w w w.java 2s . c o m * @return - a copy of str without the character c */ public static String removeCharFromString(char c, String str) { StringBuilder resultStrBuilder = new StringBuilder(str); String returnStr = ""; int charPos = str.indexOf(c); int strLen = str.length(); if ((charPos >= 0) && (strLen > 0)) { resultStrBuilder.deleteCharAt(charPos); } if (resultStrBuilder.length() > 0) { returnStr = resultStrBuilder.toString(); } return returnStr; }
From source file:com.predic8.membrane.core.util.TextUtil.java
public static Object removeFinalChar(String s) { StringBuilder sb = new StringBuilder(s); if (sb.length() > 0) sb.deleteCharAt(sb.length() - 1); return sb.toString(); }