Home>

The function is as follows:

<script type="text/javascript">
function sprintf ()
{
  var arg=arguments,    str=arg [0] || "",    i, n;
  for (i=1, n=arg.length;i<n;i ++) {
    str=str.replace (/%s /, arg [i]);
  }
  return str;
}
</script>

The first parameter is a string containing "%s",The other parameters are the corresponding variables used to replace "%s".

Such as:

<script type="text/javascript">
var str="%s bright light in front of the bed, suspected to be frosting on%s;raise your head to%s bright moon, and lower your%s hometown.",  var1="Ming",  var2="Ground",  var3="Looking",  var4="thinking";
str=sprintf (str, var1, var2, var3, var4);
</script>
  • Previous Memory management in IOS
  • Next Method for JS to read and parse JSON type data