Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.Format like C# in typescript

Tags:

typescript

Is it possible to use similar function like String.Format of C# in TypeScript?

My idea is to make some string like:

url = "path/{0}/{1}/data.xml"

depending of the logical I set {0} and {1}. Obiouslly I can replace them but I think String.Format is a clear function.

like image 239
David Avatar asked May 19 '18 18:05

David


People also ask

What are format strings in C?

Format Specifiers Used in C%c :char single character. %d (%i) :int signed integer. %e (%E) :float or double exponential format. %f :float or double signed decimal. %g (%G) :float or double use %f or %e as required.

Is string format the same as printf?

String. format returns a new String, while System. out. printf just displays the newly formatted String to System.

What is a string format?

In java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string. Syntax: There is two types of string format() method.

What is %s in printf?

%s and string We can print the string using %s format specifier in printf function. It will print the string from the given starting address to the null '\0' character. String name itself the starting address of the string. So, if we give string name it will print the entire string.


1 Answers

I think you are looking for back quote: ``

var firstname = 'Fooo';
var lastname = 'Bar';

console.log(`Hi ${firstname} ${lastname}. Welcome.`);

You can find the back quote on the tilde key. enter image description here

like image 155
Mike Bovenlander Avatar answered Sep 23 '22 21:09

Mike Bovenlander