Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there another way for replacing except for Replace() function?

In c programming language,

I can do

printf("%d\n", value);

But in c#, how can I do it? For example string is "Good %s everybody"

I want to replace %s with the variable. Are there any solution except for

str.Replace("%s","good morning");
like image 861
Göktürk Solmaz Avatar asked Dec 28 '22 13:12

Göktürk Solmaz


1 Answers

string.Format would be your function of choice.

You then could write e.g.:

const string t = "Thomas";
var s = string.Format("Good morning {0}.", t);

With {0} being replaced with the value of t.

like image 152
Uwe Keim Avatar answered Dec 30 '22 02:12

Uwe Keim