List of usage examples for java.lang StringBuffer StringBuffer
@HotSpotIntrinsicCandidate
public StringBuffer()
From source file:Main.java
public static String wrapStringByXmlType(String str) { StringBuffer sb = new StringBuffer(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sb.append(str);//from w w w . j av a 2 s .c o m return sb.toString(); }
From source file:Main.java
public static String encodeHtml(String s) { StringBuffer out = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c > 127 || c == '"' || c == '<' || c == '>') { out.append("&#" + (int) c + ";"); } else {//from ww w . ja v a2 s.c o m out.append(c); } } return out.toString(); }
From source file:Main.java
public static String ByteArrayToString(byte[] arr) { StringBuffer sb = new StringBuffer(); for (byte item : arr) { sb.append(String.format("%02X ", item & 0xFF)); }//from www. j a va2 s . c om return "{ " + sb.toString() + "}"; }
From source file:Main.java
public static String getASCII(String value) { StringBuffer sbu = new StringBuffer(); char[] chars = value.toCharArray(); for (int i = 0; i < chars.length; i++) { if (i != chars.length - 1) { sbu.append((int) chars[i]); }/*from w w w . ja va 2 s . c om*/ } return sbu.toString(); }
From source file:Main.java
public static String byte2hex(byte[] b) { StringBuffer sb = new StringBuffer(); String stmp = ""; for (int n = 0; n < b.length; n++) { stmp = Integer.toHexString(b[n] & 0XFF); if (stmp.length() == 1) { sb.append("0" + stmp); } else {/*w w w . j a v a 2 s.c om*/ sb.append(stmp); } } return sb.toString(); }
From source file:Main.java
public static String formatPhone(String number) { StringBuffer sb = new StringBuffer(); char c;/* w w w . j a v a2s . co m*/ for (int i = 0; i < number.length(); i++) { c = number.charAt(i); if (48 <= c && c <= 57) sb.append(c); } return sb.toString(); }
From source file:Main.java
public static String getCnASCII(String cnStr) { StringBuffer strBuf = new StringBuffer(); byte[] bGBK = cnStr.getBytes(); for (int i = 0; i < bGBK.length; i++) { strBuf.append(Integer.toHexString(bGBK[i] & 0xff)); }//from w w w . j a va2 s . c o m return strBuf.toString(); }
From source file:Main.java
static String makeXMLCloseElement(String elementName) { StringBuffer sb = new StringBuffer(); sb.append("</"); sb.append(elementName);/*from w w w . j ava2s. c o m*/ sb.append(">"); return sb.toString(); }
From source file:Main.java
public static String repeat(String str, int times) { StringBuffer sbf = new StringBuffer(); for (int i = 0; i < times; i++) { sbf.append(str);/*from w w w . j a v a 2 s. com*/ } return sbf.toString(); }
From source file:Main.java
private static String encodeHTML(String s) { StringBuffer out = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c > 127 || c == '"' || c == '<' || c == '>') { out.append("&#" + (int) c + ";"); } else {/* w w w . ja v a 2 s.c o m*/ out.append(c); } } return out.toString(); }