我怎么插字符串? [英] How do I interpolate strings?
本文介绍了我怎么插字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做的事情在C#以下(从一个Python背景的):
strVar =堆栈
myStr的=这是%soverflow%(strVar)
我如何更换里面的令牌与它之外的值的字符串?
解决方案
字符串myStr的=的String.Format( 这是{0}溢出,strVar);
和你也可以使用的named 的参数,而不是指标。
I want to do the following in C# (coming from a Python background):
strVar = "stack"
mystr = "This is %soverflow" % (strVar)
How do I replace the token inside the string with the value outside of it?
解决方案
string mystr = string.Format("This is {0}overflow", strVar);
And you could also use named parameters instead of indexes.
这篇关于我怎么插字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文