hideNumber static method
使用replacement
隐藏第start
到end
的位数
Implementation
static String hideNumber(
String str, {
int start = 0,
int? end,
String replacement = '*',
}) {
var buffer = StringBuffer();
if (str.length <= 1) {
return str.replaceRange(0, str.length, replacement);
}
if (end == null) {
end = (str.length / 2).round();
} else {
if (end > str.length) {
end = str.length;
}
}
for (var i = 0; i < str.length; i++) {
if (i >= end) {
buffer.write(String.fromCharCode(str.runes.elementAt(i)));
continue;
}
if (i >= start) {
buffer.write(replacement);
continue;
}
buffer.write(String.fromCharCode(str.runes.elementAt(i)));
}
return buffer.toString();
}