Skip to content

Instantly share code, notes, and snippets.

@fauxtrot
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fauxtrot/8349c9bd2708a8fa8455 to your computer and use it in GitHub Desktop.
Save fauxtrot/8349c9bd2708a8fa8455 to your computer and use it in GitHub Desktop.
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