The C# string.format function is used in many places, so I implemented a simple version using js:
{
var pattern,
length = arguments.length;
{
pattern = new RegExp( '\{' ( i - 1 ) '\}', 'g' );
formatStr = formatStr.replace(pattern, arguments[i]);
'';
}
return formatStr;
};
The above code adds a static method format to the javascript String class, and its usage is exactly the same as c#'s string.format. The test is as follows:
Copy code
Copy code
Copy code