String unconsore(String string, {int consoreLevel = 2}) {
final parts = string.split("@");
if (parts.length != 2) {
// Handle the case where there is no "@" separator in the string
return string;
}
final stringBeforeA = parts[0];
final stringAfterA = parts[1];
final unconsoredBeforeA = stringBeforeA.replaceRange(
consoreLevel, stringBeforeA.length - consoreLevel, "*" * (stringBeforeA.length - consoreLevel * 2));
return "$unconsoredBeforeA@$stringAfterA";
}
// example
print(unconsore("namesurname@mail.com")); // na*******me@mail.com
2条答案
按热度按时间kr98yfug1#
结果:
bq9c1y662#
您可以使用此方法来实现您确切想要的结果: