List of usage examples for java.lang StringBuilder StringBuilder
public StringBuilder(CharSequence seq)
From source file:Main.java
public static String replaceEntities(String s) { StringBuilder sb = new StringBuilder(s); int len = s.length(); int skip = 0; int iSkip = 0; for (int i = 0; i < len; i++) { iSkip = i + skip;//from w w w . j a v a2s . c om char c = sb.charAt(iSkip); if (c == '&') { sb.replace(iSkip, iSkip + 1, "&"); skip += 4; } else if (c == '\'') { sb.replace(iSkip, iSkip + 1, "'"); skip += 5; } else if (c == '<') { sb.replace(iSkip, iSkip + 1, "<"); skip += 3; } else if (c == '>') { sb.replace(iSkip, iSkip + 1, ">"); skip += 3; } else if (c == '"') { sb.replace(iSkip, iSkip + 1, """); skip += 5; } } return sb.toString(); }
From source file:Main.java
public static String processHexString(String inputString) { StringBuilder outPutString = new StringBuilder(""); String temp = ""; int index = inputString.indexOf("%"); while (index > -1) { temp = inputString.substring(index + 1, index + 3); outPutString = outPutString.append(inputString.substring(0, index)).append(convertHexToChar(temp)); inputString = inputString.substring(index + 3); index = inputString.indexOf("%"); }/* w w w . j a va 2s . c o m*/ return outPutString.toString(); }
From source file:Main.java
public static String byteToHexStr(byte[] b, int length) { String stmp = ""; StringBuilder sb = new StringBuilder(""); for (int n = 0; n < length; n++) { stmp = Integer.toHexString(b[n] & 0xFF); sb.append((stmp.length() == 1) ? "0" + stmp : stmp); //sb.append(" "); }// w w w .ja v a 2 s . c o m return sb.toString().toUpperCase().trim(); }
From source file:Main.java
public static String bytesToString(byte[] bytes) { StringBuilder sb = new StringBuilder(bytes.length); for (int i = 0; i < bytes.length; i++) { sb.append(String.valueOf(bytes[i])).append(" "); }/*from ww w. j ava2 s .c o m*/ return sb.toString(); }
From source file:Main.java
private static String formatAddress(byte[] addr) { StringBuilder buf = new StringBuilder(24); for (byte b : addr) { buf.append(String.format("%02x:", b & 0xff)); }//from w w w . j a v a 2s .c om return buf.substring(0, buf.length() - 1); }
From source file:Main.java
public static String byte2HexStrSpace(byte[] b, int length) { String stmp = ""; StringBuilder sb = new StringBuilder(""); for (int n = 0; n < length; n++) { stmp = Integer.toHexString(b[n] & 0xFF); sb.append((stmp.length() == 1) ? "0" + stmp : stmp); sb.append(" "); }// w ww . java 2s . co m return sb.toString().toUpperCase().trim(); }
From source file:Main.java
public static String xmlSpecialChar(String value) { StringBuilder sb = new StringBuilder(value.length()); char[] chars = value.toCharArray(); for (char c : chars) { switch (c) { case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '&': sb.append("&"); break; case '\'': sb.append("'"); break; case '"': sb.append("""); break; default:/*from w w w .jav a 2 s. c o m*/ sb.append(c); break; } } return sb.toString(); }
From source file:Main.java
public static String toString(Bundle paramBundle) { StringBuilder localStringBuilder = new StringBuilder("{"); if (paramBundle != null) { }/* w ww . ja v a 2 s .c o m*/ localStringBuilder.append("}"); return localStringBuilder.toString(); }
From source file:Main.java
public static String byte2HexStrNonSpace(byte[] b, int length) { String stmp = ""; StringBuilder sb = new StringBuilder(""); for (int n = 0; n < length; n++) { stmp = Integer.toHexString(b[n] & 0xFF); sb.append((stmp.length() == 1) ? "0" + stmp : stmp); //sb.append(" "); }/*from ww w . j a va 2 s.co m*/ return sb.toString().toUpperCase().trim(); }
From source file:Main.java
public static String addEscpage(String str) { char[] cs = str.toCharArray(); StringBuilder sb = new StringBuilder("\""); int length = cs.length; for (int i = 0; i < length; i++) { if (cs[i] == '\"' || cs[i] == '\t' || cs[i] == '\n') { sb.append("\\"); }//from ww w . ja v a 2 s . c om sb.append(cs[i]); } sb.append("\""); return sb.toString(); }