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 "--"; } } } }