formatDigitPattern static method
每隔digit
位加pattern
end
true表示从尾开始
Implementation
static String formatDigitPattern(
String str,
int digit,
String pattern, {
bool end = false,
}) {
if (end) {
String temp = reverse(str);
temp = formatDigitPattern(temp, digit, pattern);
temp = reverse(temp);
return temp;
} else {
str = str.replaceAllMapped(RegExp('(.{$digit})'), (Match match) {
return '${match.group(0)}$pattern';
});
if (pattern.isNotEmpty && str.endsWith(pattern)) {
str = str.substring(0, str.length - 1);
}
return str;
}
}