Last active
August 29, 2015 14:02
-
-
Save fauxtrot/8349c9bd2708a8fa8455 to your computer and use it in GitHub Desktop.
Typescript adaptation of http://stackoverflow.com/a/22818673/93964
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class StringHelpers { | |
static format(format: string, ...args: any[]) : string { | |
var i; | |
if (args instanceof Array) { | |
for (i = 0; i < args.length; i++) { | |
format = format.replace(new RegExp('\\{' + i + '\\}', 'gm'), args[i]); | |
} | |
return format; | |
} | |
for (i = 0; i < arguments.length - 1; i++) { | |
format = format.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i + 1]); | |
} | |
return format; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment