开发者

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

开发者 https://www.devze.com 2023-04-07 19:17 出处:网络
In c programming language, I can do printf(\"%d\\n\"开发者_如何转开发, value); But in c#, how can I do it?

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");


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消