I&QUOT能;乘"一个字符串(在C#)? [英] Can I "multiply" a string (in C#)?
本文介绍了I&QUOT能;乘"一个字符串(在C#)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个字符串,例如,
Suppose I have a string, for example,
string snip = "</li></ul>";
我要多次基本上写出来,这取决于一些整数值。
I want to basically write it multiple times, depending on some integer value.
string snip = "</li></ul>";
int multiplier = 2;
// TODO: magic code to do this
// snip * multiplier = "</li></ul></li></ul>";
编辑:
我知道我可以很容易地写我自己的函数来实现这一点,我只是想知道,如果有一些怪异的字符串操作者,我不知道
I know I can easily write my own function to implement this, I was just wondering if there was some weird string operator that I didn't know about
推荐答案
在.NET 4中,你可以这样做:
In .NET 4 you can do this:
String.Concat(Enumerable.Repeat("Hello", 4))
这篇关于I&QUOT能;乘&QUOT;一个字符串(在C#)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文