package com.weiqi.mis;

import java.util.HashMap;
import java.util.Map;

public class StringUtils {

    /**
     * 反转
     *
     * @param str
     * @return
     */
    public static String reverse(String str) {
        char[] chars = str.toCharArray();
        String reverse = "";
        for (int i = chars.length - 1; i >= 0; i--) {
            reverse += chars[i];
        }
        return reverse;
    }




    /**
     * 切割项目名称
     *
     * @param path
     * @return
     */
    public static String getPath(String path) {
//        String path1 = "/data/jiage-sms-mis/deploy/jiage-sms-mis_9081/WEB-INF/classes/";
        String patharr[] = path.split("/");
        if (patharr.length > 5) {
            return patharr[4];
        }
        return path;
    }


    /**
     * 格式化body
     *
     * @param str    目标字符串
     * @param values 储值对象
     * @return
     */
    public static String fmtByObj(String str, Map<String, String> values) {

        for (String key : values.keySet()) {
            str = str.replace("{" + key + "}", values.get(key));
        }

        return str;
    }


}
