我写了这个格式化账号的方法 :
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();
}
}
使用 < code> StringBuilder 来优化它还是已经优化了?