Javascript: How to have value in string represented by %s and then replaced with a value -


i know stupid question.

i've had few years experience javascript 1 thing seems have skipped mind, head has gone blank , can't remember it's called , how go doing it.

basically i'm looking when have string variable such as:

var error_message = "an account exists email: %s" 

and pass string somehow , replaces %s.

i sound idiotic, i'd appreciate / reminding!

thanks guys.

you use replace method:

error_message = error_message.replace('%s', email); 

this replace first occurance, if want replace multiple occurances, use regular expression can specify global (g) flag:

error_message = error_message.replace(/%s/g, email); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -