JavaScript combo string

Possible duplicate:
JavaScript equivalent of printf / string.format

I'm not sure what the exact expression is (string substitution?), But many languages ​​(C, VB, C #, etc.) offer similar mechanisms for dynamically building a string. Below is an example in C #:

string firstName = "John";
string lastName = "Doe";
string sFinal = string.Format(" Hello {0} {1} !", firstName, lastName);

I would like to do the same in JavaScript. Can anyone shed some light?

Thank,

+5
source share
1 answer

JavaScript does not yet have this functionality natively. You will need to use concatenation:

var firstName = "John";
var lastName = "Doe";
var sFinal = " Hello " + firstName + " " + lastName + " !";

Does it suck? Truth. But this is the world in which we live.


As @PeterSzymkowski pointed out, you can use this JavaScript implementation of the C / PHP functionsprintf .

+4

All Articles