javascript format 字符串 函数
函数实现如下:
function format(string) { var args = arguments; var pattern = new RegExp("%([1-" + arguments.length + "])", "g"); return String(string).replace(pattern, function (match, index) { return args[index]; }); };
用法如下:
console.log(format("And the %1 want to know whose %2 you %3", "papers", "shirt", "wear"));