Format String, "Hello {0}.".format("there") -> "Hello there." - Node.js String

Node.js examples for String:Format

Description

Format String, "Hello {0}.".format("there") -> "Hello there."

Demo Code

if (!String.prototype.format)
{
    String.prototype.format = function()
    {/*from w w w . j  a  v  a  2 s  .  co m*/
        var args = arguments;
        return this.replace(/{(\d+)}/g, function(match, number)
        {
            return typeof args[number] != 'undefined'
                ? args[number]
                : match
                ;
        });
    };
}

Related Tutorials