我目前正在创建一个 ASCII 表生成器,它是 GXP 环境中某些自动数据库报告所必需的。
鉴于我有宽度为 n 的表格行,例如:
| this | is | an | example | row |
|<-- width = 32 -->|
我现在想添加标题和间隔符,例如:
#================================#
| this | is | an | example | row |
|--------------------------------|
| 1 | 2 | 3 | 4 | 5 |
| 3 | 9 | 77 | 327814 | 2 |
|--------------------------------|
当然我可以通过以下方式做到这一点:
List<string> asciiTable = new List<string();
string topBorder = "#";
string otherBorder = "|";
for (int i = 1; i == n; i++)
{
topBorder += "=";
otherBorder += "-";
}
topBorder += "#";
otherBorder += "|";
asciiTable.Add(topBorder);
但我希望有这样的东西:
List<string> asciiTable = new List<string>();
asciiTable.Add("#" + /* add("=",n) */ + "#");
最佳答案
您可以使用 new String('=', n);
这将创建一个 string
,其中字符 '=' 重复 n 次。
关于c# - 在 C# 的字符串中间重复一个字符 n 次的最短方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52513038/