in function to repeat string or char in .net?
Is there a function in c# that returns x times of given char or string. Or I must code it?
string.Join("", Enumerable.Repeat("ab", 2));
Returns
"abab"
And
string.Join("", Enumerable.Repeat('a', 2))
Returns
"aa"
string.Concat(Enumerable.Repeat("ab", 2));
returns
"abab"
For strings you should indeed use Kirk's solution:
string.Join("", Enumerable.Repeat("ab", 2));
However for chars you might as well use the built-in (more efficient) string constructor:
new string('a', 2); // returns aa
链接地址: http://www.djcxy.com/p/21068.html
上一篇: String.Join与StringBuilder:哪个更快?
下一篇: 在函数重复字符串或字符在.NET中?