Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 除了Replace()函数,还有其他替换方法吗?_C#_Asp.net_Vb.net_String - Fatal编程技术网

C# 除了Replace()函数,还有其他替换方法吗?

C# 除了Replace()函数,还有其他替换方法吗?,c#,asp.net,vb.net,string,C#,Asp.net,Vb.net,String,在c编程语言中 我能行 printf("%d\n", value); 但在c#中,我如何才能做到这一点? 例如字符串是“Good%s everybody” 我想用变量替换%s。 除此之外还有什么解决办法吗 str.Replace("%s","good morning"); 这将是你选择的功能 然后您可以写下,例如: const string t = "Thomas"; var s = string.Format("Good morning {0}.", t); 由于将{0}替换为t的值,我

在c编程语言中

我能行

printf("%d\n", value);
但在c#中,我如何才能做到这一点? 例如字符串是“Good%s everybody”

我想用变量替换%s。 除此之外还有什么解决办法吗

str.Replace("%s","good morning");
这将是你选择的功能

然后您可以写下,例如:

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

由于将
{0}
替换为
t

的值,我在前面的示例中添加了一个内容,即如果需要几个格式字符(如printf(“%d%s%d%s”,a,b,c,d);),则必须使用括号中的参数数:string.format(“早上好{0},{1}”,t,“ru?”,“How”);另一方面,为什么对字符串t使用const?@GöktürkSolmaz这只是一个简单的例子。您可以传递任何具有
.ToString()
的内容(因为所有内容都来自
对象
并且
对象.ToString()
存在,所以所有对象都是这样)。