123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace Common
- {
- public sealed class StringHelper
- {
- /// <summary>
- /// 快速验证一个字符串是否符合指定的正则表达式。
- /// </summary>
- /// <param name="express">正则表达式的内容。</param>
- /// <param name="value">需验证的字符串。</param>
- /// <returns>是否合法的bool值。</returns>
- public static bool QuickValidate(string express, string value)
- {
- if (value == null) return false;
- var myRegex = new Regex(express);
- if (value.Length == 0)
- {
- return false;
- }
- return myRegex.IsMatch(value);
- }
- public static string GetWeeks(string weeks)
- {
- try
- {
- if (weeks == "0,1,2,3,4,5,6")
- return "每天";
- string week = "周";
- var list = weeks.Split(',');
- foreach (var item in list)
- {
- switch (item)
- {
- case "0":
- week += "一、";
- break;
- case "1":
- week += "二、";
- break;
- case "2":
- week += "三、";
- break;
- case "3":
- week += "四、";
- break;
- case "4":
- week += "五、";
- break;
- case "5":
- week += "六、";
- break;
- case "6":
- week += "日、";
- break;
- default:
- break;
- }
- }
- return week.TrimEnd('、');
- }
- catch (Exception e)
- {
- return "";
- }
- }
- /// <summary>
- /// 计算下期开奖时间
- /// </summary>
- /// <param name="weeks"></param>
- /// <returns></returns>
- public static string[] GetNextWeeks(int week,string weeks)
- {
- try
- {
- int newweek = -1;
- var list = weeks.Split(',');
- for (int i = 0; i < list.Length; i++)
- {
- if (week == Convert.ToInt32(list[i]))
- {
- if (i == list.Length - 1)
- {
- newweek = Convert.ToInt32(list[0]);
- }
- else {
- newweek = Convert.ToInt32(list[i + 1]);
- }
- }
- }
- int num = Math.Abs(week - newweek);
- return new string[2] { GetWeeks(newweek.ToString()), num.ToString() };
- }
- catch (Exception e)
- {
- return new string[2] { "", "" };
- }
- }
- public static string ToYi(string money)
- {
- try
- {
- int leg = money.Length;
- if (leg > 8)
- {
- var dc = Math.Round(money.Remove(leg - 5, 4).StrToInt() / 10000.00, 2);
- return dc + "亿";
- }
- else if (leg<=4)
- {
- return money;
- }
- else {
- var dc = Math.Round(money.Remove(leg - 5, 4).StrToInt() / 1.00, 2);
- return dc + "万";
- }
-
- }
- catch (Exception e)
- {
- return "--";
- }
- }
-
- }
- }
|