/** * 删除字符串中的数据 */ public static void testDelete() { StringBuffer sb = new StringBuffer("This is a StringBuffer!"); // 删除指定位置的字符 sb.deleteCharAt(1); sb.deleteCharAt(2); System.out.println("Delete char: " + sb.toString()); // 删除指定范围的字符串 sb.delete(1, 5); System.out.println("sb.delete(0, 5) = " + sb.toString()); }