package chapter5;

public class Example08 {
    public static void main(String[] args) {
        StringBuffer sb = new StringBuffer();

        System.out.println("1、添加------------------------");
        add(sb);
        System.out.println("2、删除------------------------");
        remove(sb);
        System.out.println("3、修改------------------------");
        alter();

    }
    public static void add(StringBuffer sb) {

        sb.append("我王小明");
        System.out.println("append添加结果：" + sb);

        sb.insert(1, "的名字是");
        System.out.println("insert添加结果：" + sb);

        sb.append("白");
        System.out.println("append添加结果：" + sb);
    }

    public static void alter() {
        StringBuffer sb = new StringBuffer("我的性别是王小白");
        sb.replace(2, 4, "姓名");
        System.out.println("替换指定位置字符串：" + sb);

        sb.setCharAt(0, '你');
        System.out.println("修改指定位置字符：" + sb);

        System.out.println("翻转：" + sb.reverse());
    }

    public static void remove(StringBuffer sb) {
        sb.delete(0, 5);
        System.out.println("delete的结果：" + sb);

        sb.deleteCharAt(3);
        System.out.println("deleteCharAt结果：" + sb);

        sb.delete(0, sb.length());
        System.out.println("清空：" + sb);
    }
}
