StringExtensions.cs 820 B

12345678910111213141516171819202122232425262728293031
  1. using System.Linq;
  2. namespace YBEE.EQM.Core;
  3. public static class StringExtensions
  4. {
  5. /// <summary>
  6. /// 清除空白字符
  7. /// </summary>
  8. /// <param name="str"></param>
  9. /// <returns></returns>
  10. public static string ClearWhitespace(this string str)
  11. {
  12. if (str == null)
  13. {
  14. return null;
  15. }
  16. return string.Concat(str.Where(c => !char.IsWhiteSpace(c)));
  17. }
  18. /// <summary>
  19. /// 证件号码规范化处理
  20. /// </summary>
  21. /// <param name="str"></param>
  22. /// <returns></returns>
  23. public static string IdNumberStdProcessing(this string str)
  24. {
  25. var nstr = ClearWhitespace(str) ?? "";
  26. nstr = nstr.Replace("(", ")").Replace(")", ")").Replace("-", "-").Replace("——", "-");
  27. return nstr.ToUpper();
  28. }
  29. }