我试图在一个基于项深度的字符串之前插入一定数量的缩进,我想知道是否有一种方法可以重复X次返回一个字符串.例:
string indent = "---";
Console.WriteLine(indent.Repeat(0)); //would print nothing.
Console.WriteLine(indent.Repeat(1)); //would print "---".
Console.WriteLine(indent.Repeat(2)); //would print "------".
Console.WriteLine(indent.Repeat(3)); //would print "---------".
Run Code Online (Sandbox Code Playgroud) 假设我有一个字符串,例如,
string snip = "</li></ul>";
Run Code Online (Sandbox Code Playgroud)
我想基本上写多次,取决于一些整数值.
string snip = "</li></ul>";
int multiplier = 2;
// TODO: magic code to do this
// snip * multiplier = "</li></ul></li></ul>";
Run Code Online (Sandbox Code Playgroud)
编辑:我知道我可以轻松编写自己的函数来实现这一点,我只是想知道是否有一些我不知道的奇怪的字符串运算符
我想在一个基于项深度的字符串之前插入一些*,我想知道是否有一种方法可以返回重复Y次的字符串.例:
string indent = "***";
Console.WriteLine(indent.Redraw(0)); //would print nothing.
Console.WriteLine(indent.Redraw(1)); //would print "***".
Console.WriteLine(indent.Redraw(2)); //would print "******".
Console.WriteLine(indent.Redraw(3)); //would print "*********".
Run Code Online (Sandbox Code Playgroud)