List of usage examples for java.lang StringBuilder length
int length();
From source file:Main.java
/** * pads a string with 'F's (useful for pinoffset management) * @param s an [hex]string//w w w.ja v a 2 s .c o m * @param len desired length * @return string right padded with 'F's */ public static String strpadf(String s, int len) { StringBuilder d = new StringBuilder(s); while (d.length() < len) d.append('F'); return d.toString(); }
From source file:Main.java
/** * pads to the right/*from w ww . j a v a2 s .c o m*/ * @param s - original string * @param len - desired len * @return space padded string */ public static String strpad(String s, int len) { StringBuilder d = new StringBuilder(s); while (d.length() < len) d.append(' '); return d.toString(); }
From source file:Main.java
public static String timeFormat(int ms) { StringBuilder time = new StringBuilder(); time.delete(0, time.length()); ms /= 1000;/* w w w . j ava 2 s .c om*/ int s = ms % 60; int min = ms / 60; if (min < 10) { time.append(0); } time.append(min).append(":"); if (s < 10) { time.append(0); } time.append(s); return time.toString(); }
From source file:Main.java
public static String toRegularHashCode(String string) { final String hexHashCode = Integer.toHexString(string.hashCode()); final StringBuilder stringBuilder = new StringBuilder(hexHashCode); while (stringBuilder.length() < 8) { stringBuilder.insert(0, '0'); }/*from w ww. j a v a 2s . co m*/ return stringBuilder.toString(); }
From source file:Main.java
public static String replace(String str, String target, String replacement) { StringBuilder sb = new StringBuilder(str); int index = sb.length(); int lenTarget = target.length(); while ((index = sb.lastIndexOf(target, index)) != -1) { sb.replace(index, index + lenTarget, replacement); index -= lenTarget;/* w w w .j a v a2 s .co m*/ } return sb.toString(); }
From source file:Main.java
public static String stripControlChars(String iString) { StringBuilder result = new StringBuilder(iString); int idx = result.length(); while (idx-- > 0) { if (result.charAt(idx) < 0x20 && result.charAt(idx) != 0x9 && result.charAt(idx) != 0xA && result.charAt(idx) != 0xD) result.deleteCharAt(idx);/*from w w w . ja v a 2s . c o m*/ } return result.toString(); }
From source file:Main.java
public static void printDetails(StringBuilder sb) { System.out.println("Content: \"" + sb + "\""); System.out.println("Length: " + sb.length()); System.out.println("Capacity: " + sb.capacity()); // Print an empty line to separate results System.out.println();//from w ww. ja va 2 s . c o m }
From source file:Main.java
public static <A> String join(Iterable<A> combination, String sep) { StringBuilder sb = new StringBuilder(); for (A s : combination) { if (sb.length() > 0) { sb.append(sep);/*w ww . jav a2s . co m*/ } sb.append(s); } return sb.toString(); }
From source file:Main.java
public static String toBrowserHexValue(int number) { StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff)); while (builder.length() < 2) { builder.append("0"); }/* w w w. j a va 2 s . c o m*/ return builder.toString().toUpperCase(); }
From source file:Main.java
public static String MACBytesToString(byte[] mac) { if (mac == null) return null; StringBuilder sb = new StringBuilder(18); for (byte b : mac) { if (sb.length() > 0) sb.append(':'); sb.append(String.format("%02x", b)); }/*from w w w . j av a 2s.com*/ return sb.toString(); }