StringBudder替换字符

package com.shucha.deveiface.biz.test;

import com.alibaba.fastjson.JSONObject;
import com.shucha.deveiface.biz.model.SysLog;
import org.apache.poi.ss.formula.functions.T;

import java.lang.reflect.Type;
import java.util.LinkedList;
import java.util.List;

/**
 * @author tqf
 * @Description 字符串替换   1000000   10111111
 * @Version 1.0
 * @since 2023-05-16 16:25
 */
public class StringBudder {
    public static void main(String[] args) {
        StringBuffer buffer = new StringBuffer("0000000000");
        // System.out.println(buffer.replace(2,3,"2").toString());
        List list = new LinkedList<>();
        list.add(0);
        list.add(2);
        list.add(3);
        System.out.println(replaceData(buffer, list, "2"));
        String os = System.getProperty("os.name");
        System.out.println(os);

        String str = "{\n" +
                "\t\"id\":1,\n" +
                "\t\"userId\":14,\n" +
                "\t\"requestData\":\"请求参数\"\n" +
                "}";
        getData(str, SysLog.class);
    }


    /**
     * 字符串替换
     * @param buffer 原始数据
     * @param list 替换的位置,从0开始
     * @param str 替换后的字符
     * @return
     */
    public static String replaceData(StringBuffer buffer, List list, String str){
        for (int i = 0; i < list.size(); i++) {
            Integer start = list.get(i);
            Integer end = start + 1;
            buffer.replace(start,end,str);
        }
        return buffer.toString();
    }

    public static Object getData(String str, Class dataClass){
        Object data = JSONObject.parseObject(str, dataClass);
        return data;
    }
}

你可能感兴趣的:(java,开发语言)