123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using System;
- using System.Collections.Generic;
- using System.Security.Cryptography;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace VaporRecoveryOnlineWatchHubApp
- {
- public static class Util
- {
-
- public static decimal Round<T>(T input, int digits = 2)
- {
- return Math.Round(Convert.ToDecimal(input), digits, MidpointRounding.AwayFromZero);
- }
-
- public static double RoundToDouble<T>(T input, int digits = 2)
- {
- return (double)Math.Round(Convert.ToDecimal(input), digits, MidpointRounding.AwayFromZero);
- }
- }
- public static class StringExtension
- {
-
-
-
-
-
-
-
-
-
- public static string ToSBC(this string input)
- {
-
- char[] c = input.ToCharArray();
- for (int i = 0; i < c.Length; i++)
- {
- if (c[i] == 32)
- {
- c[i] = (char)12288;
- continue;
- }
- if (c[i] < 127)
- c[i] = (char)(c[i] + 65248);
- }
- return new string(c);
- }
-
-
-
-
-
-
-
-
-
-
- public static string ToDBC(this string input)
- {
- char[] c = input.ToCharArray();
- for (int i = 0; i < c.Length; i++)
- {
- if (c[i] == 12288)
- {
- c[i] = (char)32;
- continue;
- }
- if (c[i] > 65280 && c[i] < 65375)
- c[i] = (char)(c[i] - 65248);
- }
- return new string(c);
- }
-
- public static string RemoveSpaces(this string input)
- {
- return input.Replace(" ", "");
- }
-
- public static string RemoveStringList(this string input, List<string> strList)
- {
- var output = input;
- strList.ForEach(s => {
- output = output.Replace(s, "");
- });
- return output;
- }
-
- public static string RemovePrefixString(this string self, string str)
- {
- string strRegex = @"^(" + str + ")";
- return Regex.Replace(self, strRegex, "");
- }
-
- public static string RemoveSuffixString(this string self, string str)
- {
- string strRegex = @"(" + str + ")" + "$";
- return Regex.Replace(self, strRegex, "");
- }
-
- public static bool IsEmail(this string self)
- {
- return self.RegexMatch(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
- }
-
- public static bool IsDomain(this string self)
- {
- return self.RegexMatch(@"[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?");
- }
-
- public static bool IsIP(this string self)
- {
- return self.RegexMatch(@"((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))");
- }
-
- public static bool IsMobilePhone(this string self)
- {
- return self.RegexMatch(@"^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$");
- }
-
- public static bool RegexMatch(this string slef, string pattern)
- {
- Regex reg = new Regex(pattern);
- return reg.Match(slef).Success;
- }
-
- public static string ConvertToMD5(this string self, string flag = "x2")
- {
- byte[] sor = Encoding.UTF8.GetBytes(self);
- MD5 md5 = MD5.Create();
- byte[] result = md5.ComputeHash(sor);
- StringBuilder strbul = new StringBuilder(40);
- for (int i = 0; i < result.Length; i++)
- {
- strbul.Append(result[i].ToString(flag));
- }
- return strbul.ToString();
- }
-
- public static string ConvertToMD5_32(this string self)
- {
- return ConvertToMD5(self, "x2");
- }
-
- public static string ConvertToMD5_48(this string self)
- {
- return ConvertToMD5(self, "x3");
- }
-
- public static string ConvertToMD5_64(this string self)
- {
- return ConvertToMD5(self, "x4");
- }
- }
- }
|