Return to Snippet

Revision: 30208
at August 10, 2010 04:24 by rmariuzzo


Initial Code
/**
 * Format a string with an array of arguments.
 * 
 * @param msg A string.
 * @return A formatted string
 */
function format(msg) {
    if (arguments && arguments.length > 1) {
        for (var i = 1; i < arguments.length; i++) {
            msg = msg.replace('{'+(i-1)+'}', arguments[i]);
        }
    }
    return msg;
}

Initial URL
http://mariuzzo.com/

Initial Description

                                

Initial Title
Format a string with an array of arguments

Initial Tags
javascript, format, text

Initial Language
JavaScript