List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:Main.java
private static String join(int length) { StringBuffer sb = new StringBuffer(1024); for (int i = 0; i < length; i++) { sb.append("?,"); }//ww w . j a v a 2 s . co m if (sb.charAt(sb.length() - 1) == ',') { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:Main.java
public static String listToString(List<String> weeks) { if (weeks == null || weeks.isEmpty()) { return ""; }//from w ww .j a v a 2 s. c o m StringBuffer result = new StringBuffer(); for (String week : weeks) { result.append(week).append(","); } if (result.length() != 0) { result.deleteCharAt(result.length() - 1); } return result.toString(); }
From source file:Main.java
public static String numberCheck(String num) { if (num == null || num.length() == 0) { return ""; }// w ww .j a v a2s . c om Pattern pattern = Pattern.compile("(?<!\\d)(?:(?:1[34578]\\d{9})|(?:861[34578]\\d{9}))(?!\\d)"); Matcher matcher = pattern.matcher(num); StringBuffer bf = new StringBuffer(64); while (matcher.find()) { bf.append(matcher.group()).append(","); } int len = bf.length(); if (len > 0) { bf.deleteCharAt(len - 1); } return bf.toString(); }
From source file:Main.java
public static String getMapAppendUrl(Map<String, String> params) { StringBuffer sb1 = new StringBuffer(); for (String key : params.keySet()) { sb1.append(key);/*from w w w . ja v a2 s . c o m*/ sb1.append("="); sb1.append((String) params.get(key)); sb1.append("&"); } sb1.deleteCharAt(sb1.length() - 1); return sb1.toString(); }
From source file:Util.java
public static String isoDateTimeToDate(String isoDate) { StringBuffer sb = new StringBuffer(isoDate); int maxlen;//from w w w . j a v a2s. c o m if (isoDate.length() >= 10) { //2007-01-01 -> 20070101 //remove hyphens between year, month, and day sb.deleteCharAt(4); sb.deleteCharAt(6); maxlen = 8; //20070101T17:30:12 -> 20070101T173012 if (isoDate.length() >= 19) { maxlen = 15; //remove colons between hours, minutes, and seconds sb.deleteCharAt(11); sb.deleteCharAt(13); if (isoDate.indexOf("Z") >= 0) { sb.insert(15, 'Z'); ++maxlen; } } if (sb.length() > maxlen) sb.setLength(maxlen); } return sb.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 ww w . j a v a 2 s .com stringBuffer.deleteCharAt(stringBuffer.lastIndexOf("\n")); return stringBuffer.toString(); }
From source file:fr.cls.atoll.motu.library.converter.jaxb.LocaleAdapter.java
/** * Trim all occurences of the supplied leading character from the given String. * //from ww w. j a v a 2s.c o m * @param str the String to check * @param leadingCharacter the leading character to be trimmed * @return the trimmed String */ private static String trimLeadingCharacter(String str, char leadingCharacter) { if (StringUtils.isEmpty(str)) { return str; } StringBuffer buf = new StringBuffer(str); while (buf.length() > 0 && buf.charAt(0) == leadingCharacter) { buf.deleteCharAt(0); } return buf.toString(); }
From source file:Main.java
private static String convertStringToTime(String oldTime) { if (oldTime == null || oldTime.length() == 0) { return "00h00m00s"; }//from w ww . jav a 2 s . co m boolean hasHours = (oldTime.indexOf('h') != -1); boolean hasMinutes = (oldTime.indexOf('m') != -1); StringBuffer rtn = new StringBuffer(oldTime); // Delete the seconds fields and replace other chars with colons rtn.deleteCharAt(oldTime.indexOf('s')); if (hasMinutes) { rtn.setCharAt(oldTime.indexOf('m'), ':'); } else { rtn.insert(0, "00:"); } if (hasHours) { rtn.setCharAt(oldTime.indexOf('h'), ':'); } else { rtn.insert(0, "00:"); } StringTokenizer st = new StringTokenizer(rtn.toString(), ":"); int index = 1; String hh = "00"; String mm = "00"; String ss = "00"; while (st.hasMoreTokens()) { String toke = st.nextToken(); switch (index) { case 1: if (toke.length() < 2) { hh = "0" + toke; } else { hh = toke; } break; case 2: if (toke.length() < 2) { mm = "0" + toke; } else { mm = toke; } break; case 3: if (toke.length() < 2) { ss = "0" + toke; } else { ss = toke; } break; } index++; } return hh + "h" + mm + "m" + ss + "s"; }
From source file:Main.java
public static String MapToUrl(Map<?, ?> data) { StringBuffer queryString = new StringBuffer(); for (Map.Entry<?, ?> pair : data.entrySet()) { queryString.append(pair.getKey() + "="); queryString.append(pair.getValue() + "&"); }//from w w w .j ava 2 s . c o m if (queryString.length() > 0) { queryString.deleteCharAt(queryString.length() - 1); } return queryString.toString(); }
From source file:org.coury.jfilehelpers.helpers.StringHelper.java
public static String trimEnd(final String s, final char[] toTrim) { char[] sChars = s.toCharArray(); String toTrimStr = new String(toTrim); StringBuffer sb = new StringBuffer(s); for (int i = sChars.length - 1; i >= 0; i--) { if (toTrimStr.indexOf(sChars[i]) > -1) { sb.deleteCharAt(i); } else {// www. jav a 2 s.c o m break; } } return sb.toString(); }