StringExtension.cs 913 B

12345678910111213141516171819202122232425262728293031323334
  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. s.Ok();
  17. }
  18. /// <summary>
  19. /// 判断字符串 非null、""、空格(Not NullOrWhiteSpace)
  20. /// </summary>
  21. /// <param name="s"></param>
  22. /// <returns></returns>
  23. public static bool Ok(this String s)
  24. {
  25. return Str.Ok(s);
  26. }
  27. public static int WordCount(this String str)
  28. {
  29. return str.Split(new char[] { ' ', '.', '?' },
  30. StringSplitOptions.RemoveEmptyEntries).Length;
  31. }
  32. }
  33. }