我想"美化"我的一个Dart脚本的输出,如下所示:
-----------------------------------------
OpenPGP signing notes from key `CD42FF00`
-----------------------------------------
<Paragraph>
我想知道printing the same character 100 times in Dart是否有一种特别简单和/或优化的方式.在Python中,print "-" * x
将打印"-"
个字符x
次.
学习this answer,出于这个问题的目的,我编写了以下使用核心Iterable
类的最小代码:
main() {
// Obtained with '-'.codeUnitAt(0)
const int FILLER_CHAR = 45;
String headerTxt;
Iterable headerBox;
headerTxt = 'OpenPGP signing notes from key `CD42FF00`';
headerBox = new Iterable.generate(headerTxt.length, (e) => FILLER_CHAR);
print(new String.fromCharCodes(headerBox));
print(headerTxt);
print(new String.fromCharCodes(headerBox));
// ...
}
这给出了预期的输出,但是is there a better way英寸的省道可以打印一个字符(或字符串)x
次吗?在我的示例中,我想将"-"
个字符打印headerTxt.length
次.