StringExtension.cs 893 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Azylee.Core.DataUtils.StringUtils
  6. {
  7. /// <summary>
  8. /// String类型扩展方法
  9. /// </summary>
  10. public static class StringExtension
  11. {
  12. private static void Test()
  13. {
  14. string s = "Hello Extension Methods";
  15. int i = s.WordCount();
  16. }
  17. /// <summary>
  18. /// 判断字符串 非null、""、空格(Not NullOrWhiteSpace)
  19. /// </summary>
  20. /// <param name="s"></param>
  21. /// <returns></returns>
  22. public static bool Ok(this String s)
  23. {
  24. return Str.Ok(s);
  25. }
  26. public static int WordCount(this String str)
  27. {
  28. return str.Split(new char[] { ' ', '.', '?' },
  29. StringSplitOptions.RemoveEmptyEntries).Length;
  30. }
  31. }
  32. }