formatDigitPattern static method
每隔 x位 加 pattern。比如用来格式化银行卡
Implementation
static String formatDigitPattern(String? text,
{int digit = 4, String pattern = ' '}) {
if (isEmpty(text)) {
return "";
}
text = text!.replaceAllMapped(RegExp('(.{$digit})'), (Match match) {
return '${match.group(0)}$pattern';
});
if (text.endsWith(pattern)) {
text = text.substring(0, text.length - 1);
}
return text;
}