repeat method
Repeats this string count times.
Uses a StringBuffer for efficient concatenation. Returns an empty string
if count is zero or negative, or if this string is empty.
Args:
count: The number of times to repeat the string.
Returns:
A new string containing this string repeated count times.
Example:
'abc'.repeat(3); // 'abcabcabc'
'x'.repeat(5); // 'xxxxx'
'test'.repeat(0); // ''
'test'.repeat(-1); // ''
Implementation
String repeat(int count) {
if (isEmpty || count <= 0) return '';
final StringBuffer buffer = StringBuffer();
for (int i = 0; i < count; i++) {
buffer.write(this);
}
return buffer.toString();
}