javascript版string.Format
原文发布时间为:2011-03-28 —— 来源于本人的百度文章 [由搬家工具导入]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var string = {
Format: function (str) {
for (i = 1; i < arguments.length; i++) {
str = str.replace('{' + (i - 1) + '}', arguments[i]);
}
return str;
}
}
</script>
</head>
<body>
<div>
<script type="text/javascript">
alert(string.Format("NjayWu: {0} {1} !", "Hello", "World"));
</script>
</div>
</body>
</html>