StringHelper.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8. namespace Common
  9. {
  10. public sealed class StringHelper
  11. {
  12. /// <summary>
  13. /// 快速验证一个字符串是否符合指定的正则表达式。
  14. /// </summary>
  15. /// <param name="express">正则表达式的内容。</param>
  16. /// <param name="value">需验证的字符串。</param>
  17. /// <returns>是否合法的bool值。</returns>
  18. public static bool QuickValidate(string express, string value)
  19. {
  20. if (value == null) return false;
  21. var myRegex = new Regex(express);
  22. if (value.Length == 0)
  23. {
  24. return false;
  25. }
  26. return myRegex.IsMatch(value);
  27. }
  28. public static string GetWeeks(string weeks)
  29. {
  30. try
  31. {
  32. if (weeks == "0,1,2,3,4,5,6")
  33. return "每天";
  34. string week = "周";
  35. var list = weeks.Split(',');
  36. foreach (var item in list)
  37. {
  38. switch (item)
  39. {
  40. case "0":
  41. week += "一、";
  42. break;
  43. case "1":
  44. week += "二、";
  45. break;
  46. case "2":
  47. week += "三、";
  48. break;
  49. case "3":
  50. week += "四、";
  51. break;
  52. case "4":
  53. week += "五、";
  54. break;
  55. case "5":
  56. week += "六、";
  57. break;
  58. case "6":
  59. week += "日、";
  60. break;
  61. default:
  62. break;
  63. }
  64. }
  65. return week.TrimEnd('、');
  66. }
  67. catch (Exception e)
  68. {
  69. return "";
  70. }
  71. }
  72. /// <summary>
  73. /// 计算下期开奖时间
  74. /// </summary>
  75. /// <param name="weeks"></param>
  76. /// <returns></returns>
  77. public static string[] GetNextWeeks(int week,string weeks)
  78. {
  79. try
  80. {
  81. int newweek = -1;
  82. var list = weeks.Split(',');
  83. for (int i = 0; i < list.Length; i++)
  84. {
  85. if (week == Convert.ToInt32(list[i]))
  86. {
  87. if (i == list.Length - 1)
  88. {
  89. newweek = Convert.ToInt32(list[0]);
  90. }
  91. else {
  92. newweek = Convert.ToInt32(list[i + 1]);
  93. }
  94. }
  95. }
  96. int num = Math.Abs(week - newweek);
  97. return new string[2] { GetWeeks(newweek.ToString()), num.ToString() };
  98. }
  99. catch (Exception e)
  100. {
  101. return new string[2] { "", "" };
  102. }
  103. }
  104. public static string ToYi(string money)
  105. {
  106. try
  107. {
  108. int leg = money.Length;
  109. if (leg > 8)
  110. {
  111. var dc = Math.Round(money.Remove(leg - 5, 4).StrToInt() / 10000.00, 2);
  112. return dc + "亿";
  113. }
  114. else if (leg<=4)
  115. {
  116. return money;
  117. }
  118. else {
  119. var dc = Math.Round(money.Remove(leg - 5, 4).StrToInt() / 1.00, 2);
  120. return dc + "万";
  121. }
  122. }
  123. catch (Exception e)
  124. {
  125. return "--";
  126. }
  127. }
  128. }
  129. }