我已经编写了这种格式化帐号的方法:
public static string FormatAccountNumber(string accountNumber)
{
if (string.IsNullOrEmpty(accountNumber))
return string.Empty;
if (accountNumber.Length < 4)
return "****";
else
{
StringBuilder stringBuilder = new StringBuilder();
int starLength = accountNumber.Length - 4;
for (int index = 0; index < starLength; index++)
stringBuilder.Append("*");
stringBuilder.Append(accountNumber.Substring(accountNumber.Length - 4));
return stringBuilder.ToString();
}
}
这可以优化还是已经通过使用优化StringBuilder
?