public static String replace(String str, char[] arg) { int argIndex = 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == '%' && i < str.length() - 1 && str.charAt(i + 1) == 's') { if (argIndex < arg.length) { sb.append(arg[argIndex++]); } else { sb.append("%s"); } i++; // 跳过占位符后面的 "s" } else { sb.append(str.charAt(i)); } } return sb.toString(); }


原文地址: http://www.cveoy.top/t/topic/bux5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录