TextUtils.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace efunbox_xyyf_windows.util
  7. {
  8. public class TextUtils
  9. {
  10. //非空判断
  11. public static bool isEmpty(string str)
  12. {
  13. if (str == null || str.Equals("") || str.Length == 0)
  14. {
  15. return true;
  16. }
  17. else
  18. {
  19. return false;
  20. }
  21. }
  22. /**
  23. * 获取字符串
  24. * N 字符数量; 默认32位
  25. * number: 是否包含数字; 默认true
  26. * Lowercase:是否包含小写英文字母 默认false
  27. * capital:是否包含大写英文字母 默认true
  28. *
  29. * **/
  30. public static string GetRandomCharacters(int n = 32, bool Number = true, bool Lowercase = false, bool Capital = true)
  31. {
  32. StringBuilder tmp = new StringBuilder();
  33. Random rand = new Random();
  34. string characters = (Capital ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : null) + (Number ? "0123456789" : null) + (Lowercase ? "abcdefghijklmnopqrstuvwxyz" : null);
  35. if (characters.Length < 1)
  36. {
  37. return (null);
  38. }
  39. for (int i = 0; i < n; i++)
  40. {
  41. tmp.Append(characters[rand.Next(0, characters.Length)].ToString());
  42. }
  43. return (tmp.ToString());
  44. }
  45. }
  46. }