List of usage examples for java.lang StringBuffer StringBuffer
public StringBuffer(CharSequence seq)
From source file:Main.java
public static String createRequestResponseXML(String resCode, String resDesc) { StringBuffer xmlContent = new StringBuffer( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?><Root><ServCont><Response>"); xmlContent.append("<Result>").append(resCode).append("</Result>"); xmlContent.append("<Description>").append(resDesc).append("</Description>"); xmlContent.append("</Response></ServCont></Root>"); return xmlContent.toString(); }
From source file:Main.java
public static void print(String a[][]) { if (a != null) { StringBuffer result = new StringBuffer("Array printer:"); for (int i = 0; i < a.length; i++) { result.append("\n").append(i).append(":"); for (int j = 0; j < a[i].length; j++) result.append(" [").append(a[i][j]).append("]"); }//from ww w . j ava 2 s.c o m //System.out.println(result.toString()); } else { //System.out.println("Array printer: null"); } }
From source file:Main.java
public static String bcd2Str(byte[] bytes) { StringBuffer temp = new StringBuffer(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { temp.append((byte) ((bytes[i] & 0xf0) >>> 4)); temp.append((byte) (bytes[i] & 0x0f)); }/*www . ja v a 2 s. c o m*/ return temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp.toString().substring(1) : temp.toString(); }
From source file:Main.java
public static String toMacFormat(String mac) { if (mac.length() == 12) { StringBuffer sb = new StringBuffer(mac); sb.insert(10, ':'); sb.insert(8, ':'); sb.insert(6, ':'); sb.insert(4, ':'); sb.insert(2, ':'); return sb.toString(); }/* w ww . j a v a 2s. co m*/ return ""; }
From source file:Main.java
public static String byteArrayToHexString(byte[] b) { StringBuffer sb = new StringBuffer(b.length * 2); for (int i = 0; i < b.length; i++) { int v = b[i] & 0xff; if (v < 16) { sb.append('0'); }/*from w w w.j a va 2 s . c o m*/ sb.append(Integer.toHexString(v)); } return sb.toString().toUpperCase(); }
From source file:Main.java
/** * // ww w . jav a 2s .c o m * @param str * @return */ public static String strRev(String str) { StringBuffer sb = new StringBuffer(str); String newstr = sb.reverse().toString(); return newstr; }
From source file:Main.java
public static String subTel(String number) { if (number != null && number.length() == 11) { StringBuffer buffer = new StringBuffer(number); StringBuffer replace = buffer.replace(3, 7, "****"); return replace.toString(); }//from w w w.j ava 2s . c o m return null; }
From source file:Main.java
public static String spliteMobile(String mobile) { StringBuffer buffer = new StringBuffer(mobile); char[] chars = buffer.reverse().toString().toCharArray(); StringBuffer result = new StringBuffer(); for (int i = chars.length - 1; i >= 0; i--) { if (i % 4 == 0) { result.append(chars[i]).append(" "); } else {//from www . j a v a2 s. co m result.append(chars[i]); } } return result.toString(); }
From source file:Main.java
public static String checkXMLSting(String origStr) { byte[] origBytes = origStr.getBytes(); StringBuffer sb = new StringBuffer(origBytes.length); for (int i = 0; i < origBytes.length; i++) { System.out.println(i + " =" + String.valueOf(origBytes[i])); if (origBytes[i] < 0) sb.append(" "); else/*from w ww . j av a2 s. c o m*/ sb.append(origStr.substring(i, i + 1)); } return sb.toString(); }
From source file:Main.java
public static String toHex(byte[] to) { if (null == to || to.length == 0) return "[]"; StringBuffer sb = new StringBuffer("[" + Integer.toHexString(to[0] & 0xFF)); for (int i = 1; i < to.length; i++) { sb.append(String.format(" %02x", to[i] & 0xFF)); }// w ww.j av a 2 s . com sb.append("]"); return sb.toString(); }