将某个字符出现 x 次的次数添加到字符串中的最佳/推荐方法是什么,例如
String header = "HEADER";
header 变量需要在其末尾添加,比方说 100 个 0
。但这个数字会根据其他因素而改变。
最佳答案
怎么样:
header += new string('0', 100);
当然;如果您要进行多项操作,请考虑 StringBuilder
:
StringBuilder sb = new StringBuilder("HEADER");
sb.Append('0', 100); // (actually a "fluent" API if you /really/ want...)
// other manipluations/concatenations (Append) here
string header = sb.ToString();
关于C# 将字符的 x 次出现附加到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1404595/