Kra!
I would like to “decorate” the output of one of my Dart scripts, for example:
----------------------------------------- OpenPGP signing notes from key `CD42FF00` ----------------------------------------- <Paragraph>
And I wonder if there is a particularly simple and / or optimized way to print the same character x times in Dart . In Python, print "-" * x will print the character - x .
Studying this answer , for this question I wrote the following minimal code that uses the Iterable main class:
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)); // ... }
This gives the expected result, but is there a better way in Dart to print a character (or string) x times? In my example, I want to print the character - headerTxt.length .
Thanks.
source share