除了Replace()函数之外,还有其他的替换方法吗?
本文关键字:其他 替换 方法 Replace 函数 除了 | 更新日期: 2023-09-27 18:09:33
在c语言中
I can do
printf("%d'n", value);
但是在c#中,我怎么做呢?例如字符串是"Good %s everybody"
我想用变量替换%s。除了
还有别的解决办法吗?str.Replace("%s","good morning");
string.Format
是您选择的函数。
你可以这样写:
const string t = "Thomas";
var s = string.Format("Good morning {0}.", t);
将{0}
替换为t
的值