Thomas Darimont
Erfahrenes Mitglied
Hallo,
hier mal ein kleines Beispiel für bequemes Ersetzen von Platzhaltern in sprintf like Format-Strings (derzeit nur %s unterstützt).
Gruß Tom
hier mal ein kleines Beispiel für bequemes Ersetzen von Platzhaltern in sprintf like Format-Strings (derzeit nur %s unterstützt).
Javascript:
function sprintf(format, a, b, c, d, e, f){
if (format === undefined) {
return "";
}
var args = [a, b, c, d, e, f];
var idx = 0;
return format.replace(/%s/g, function() { return args[idx++]; });
}
//Usage
sprintf("Key: %s, value: %s", "foo","bar")
//Output
// "Key: foo, value: bar"
Gruß Tom