desensitize static method

String desensitize(
  1. String str, {
  2. int start = 0,
  3. int? end,
  4. String replace = '*',
})

字符串脱敏处理 Desensitize string

Implementation

static String desensitize(String str, {int start = 0, int? end, String replace = '*'}) {
  end ??= str.length;
  if (start < 0) start = 0;
  if (end > str.length) end = str.length;
  if (start >= end) return str;
  return str.replaceRange(start, end, replace * (end - start));
}