为大家分享一下个人的一个Utils系统帮助类,可能有些现在有新的技术替代,自行修改哈~
这个帮助类主要包含:对象转换处理 、分割字符串、截取字符串、删除最后结尾的一个逗号、 删除最后结尾的指定字符后的字符、 生成指定长度的字符串、 生成日期随机码、 生成随机字母或数、字 截取字符长度、 对象<-->JSON 4.0使用、 对象<-->JSON 2.0使用litjson插件、 DataTable<-->JSON、 List<--->DataTable、 清除HTML标记、 清除HTML标记且返回相应的长度、 TXT代码转换成HTML格式、 HTML代码转换成TXT格式、 检测是否有Sql危险字符、 过滤特殊字符、 检查是否为IP地址、 获得配置文件节点XML文件的绝对路径、 获得当前绝对路径、 文件操作、 读取或写入cookie 替换指定的字符串、 URL处理、 MD5加密方法、 获得当前页面客户端的IP、 数据导出为EXCEL、 列的命名、 构造URL POST请求、 构造URL GET请求、 POST请求、 访问提交创建文件 (供生成静态页面使用,无需模板)、 汉字转拼音、 获取网页的HTML内容
废话不多说,上代码:
对象转换处理
1 #region 对象转换处理 2 /// <summary> 3 /// 判断对象是否为Int32类型的数字 4 /// </summary> 5 /// <param name="Expression"></param> 6 /// <returns></returns> 7 public static bool IsNumeric(object expression) 8 { 9 if (expression != null) 10 return IsNumeric(expression.ToString()); 11 12 return false; 13 14 } 15 16 /// <summary> 17 /// 判断对象是否为Int32类型的数字 18 /// </summary> 19 /// <param name="Expression"></param> 20 /// <returns></returns> 21 public static bool IsNumeric(string expression) 22 { 23 if (expression != null) 24 { 25 string str = expression; 26 if (str.Length > 0 && str.Length <= 11 && Regex.IsMatch(str, @"^[-]?[0-9]*[.]?[0-9]*$")) 27 { 28 if ((str.Length < 10) || (str.Length == 10 && str[0] == '1') || (str.Length == 11 && str[0] == '-' && str[1] == '1')) 29 return true; 30 } 31 } 32 return false; 33 } 34 35 /// <summary> 36 /// 是否为Double类型 37 /// </summary> 38 /// <param name="expression"></param> 39 /// <returns></returns> 40 public static bool IsDouble(object expression) 41 { 42 if (expression != null) 43 return Regex.IsMatch(expression.ToString(), @"^([0-9])[0-9]*(\.\w*)?$"); 44 45 return false; 46 } 47 48 /// <summary> 49 /// 将字符串转换为数组 50 /// </summary> 51 /// <param name="str">字符串</param> 52 /// <returns>字符串数组</returns> 53 public static string[] GetStrArray(string str) 54 { 55 return str.Split(new char[',']); 56 } 57 58 /// <summary> 59 /// 将数组转换为字符串 60 /// </summary> 61 /// <param name="list">List</param> 62 /// <param name="speater">分隔符</param> 63 /// <returns>String</returns> 64 public static string GetArrayStr(List<string> list, string speater) 65 { 66 StringBuilder sb = new StringBuilder(); 67 for (int i = 0; i < list.Count; i++) 68 { 69 if (i == list.Count - 1) 70 { 71 sb.Append(list[i]); 72 } 73 else 74 { 75 sb.Append(list[i]); 76 sb.Append(speater); 77 } 78 } 79 return sb.ToString(); 80 } 81 82 /// <summary> 83 /// object型转换为bool型 84 /// </summary> 85 /// <param name="strValue">要转换的字符串</param> 86 /// <param name="defValue">缺省值</param> 87 /// <returns>转换后的bool类型结果</returns> 88 public static bool StrToBool(object expression, bool defValue) 89 { 90 if (expression != null) 91 return StrToBool(expression, defValue); 92 93 return defValue; 94 } 95 96 /// <summary> 97 /// string型转换为bool型 98 /// </summary> 99 /// <param name="strValue">要转换的字符串</param> 100 /// <param name="defValue">缺省值</param> 101 /// <returns>转换后的bool类型结果</returns> 102 public static bool StrToBool(string expression, bool defValue) 103 { 104 if (expression != null) 105 { 106 if (string.Compare(expression, "true", true) == 0) 107 return true; 108 else if (string.Compare(expression, "false", true) == 0) 109 return false; 110 } 111 return defValue; 112 } 113 114 /// <summary> 115 /// 将对象转换为Int32类型 116 /// </summary> 117 /// <param name="expression">要转换的字符串</param> 118 /// <param name="defValue">缺省值</param> 119 /// <returns>转换后的int类型结果</returns> 120 public static int ObjToInt(object expression, int defValue) 121 { 122 if (expression != null) 123 return StrToInt(expression.ToString(), defValue); 124 125 return defValue; 126 } 127 128 /// <summary> 129 /// 将字符串转换为Int32类型 130 /// </summary> 131 /// <param name="expression">要转换的字符串</param> 132 /// <param name="defValue">缺省值</param> 133 /// <returns>转换后的int类型结果</returns> 134 public static int StrToInt(string expression, int defValue) 135 { 136 if (string.IsNullOrEmpty(expression) || expression.Trim().Length >= 11 || !Regex.IsMatch(expression.Trim(), @"^([-]|[0-9])[0-9]*(\.\w*)?$")) 137 return defValue; 138 139 int rv; 140 if (Int32.TryParse(expression, out rv)) 141 return rv; 142 143 return Convert.ToInt32(StrToFloat(expression, defValue)); 144 } 145 146 /// <summary> 147 /// Object型转换为decimal型 148 /// </summary> 149 /// <param name="strValue">要转换的字符串</param> 150 /// <param name="defValue">缺省值</param> 151 /// <returns>转换后的decimal类型结果</returns> 152 public static decimal ObjToDecimal(object expression, decimal defValue) 153 { 154 if (expression != null) 155 return StrToDecimal(expression.ToString(), defValue); 156 157 return defValue; 158 } 159 160 /// <summary> 161 /// string型转换为decimal型 162 /// </summary> 163 /// <param name="strValue">要转换的字符串</param> 164 /// <param name="defValue">缺省值</param> 165 /// <returns>转换后的decimal类型结果</returns> 166 public static decimal StrToDecimal(string expression, decimal defValue) 167 { 168 if ((expression == null) || (expression.Length > 10)) 169 return defValue; 170 171 decimal intValue = defValue; 172 if (expression != null) 173 { 174 bool IsDecimal = Regex.IsMatch(expression, @"^([-]|[0-9])[0-9]*(\.\w*)?$"); 175 if (IsDecimal) 176 decimal.TryParse(expression, out intValue); 177 } 178 return intValue; 179 } 180 181 /// <summary> 182 /// Object型转换为float型 183 /// </summary> 184 /// <param name="strValue">要转换的字符串</param> 185 /// <param name="defValue">缺省值</param> 186 /// <returns>转换后的int类型结果</returns> 187 public static float ObjToFloat(object expression, float defValue) 188 { 189 if (expression != null) 190 return StrToFloat(expression.ToString(), defValue); 191 192 return defValue; 193 } 194 195 /// <summary> 196 /// string型转换为float型 197 /// </summary> 198 /// <param name="strValue">要转换的字符串</param> 199 /// <param name="defValue">缺省值</param> 200 /// <returns>转换后的int类型结果</returns> 201 public static float StrToFloat(string expression, float defValue) 202 { 203 if ((expression == null) || (expression.Length > 10)) 204 return defValue; 205 206 float intValue = defValue; 207 if (expression != null) 208 { 209 bool IsFloat = Regex.IsMatch(expression, @"^([-]|[0-9])[0-9]*(\.\w*)?$"); 210 if (IsFloat) 211 float.TryParse(expression, out intValue); 212 } 213 return intValue; 214 } 215 216 /// <summary> 217 /// 将对象转换为日期时间类型 218 /// </summary> 219 /// <param name="str">要转换的字符串</param> 220 /// <param name="defValue">缺省值</param> 221 /// <returns>转换后的int类型结果</returns> 222 public static DateTime StrToDateTime(string str, DateTime defValue) 223 { 224 if (!string.IsNullOrEmpty(str)) 225 { 226 DateTime dateTime; 227 if (DateTime.TryParse(str, out dateTime)) 228 return dateTime; 229 } 230 return defValue; 231 } 232 233 /// <summary> 234 /// 将对象转换为日期时间类型 235 /// </summary> 236 /// <param name="str">要转换的字符串</param> 237 /// <returns>转换后的int类型结果</returns> 238 public static DateTime StrToDateTime(string str) 239 { 240 return StrToDateTime(str, DateTime.Now); 241 } 242 243 /// <summary> 244 /// 将对象转换为日期时间类型 245 /// </summary> 246 /// <param name="obj">要转换的对象</param> 247 /// <returns>转换后的int类型结果</returns> 248 public static DateTime ObjectToDateTime(object obj) 249 { 250 return StrToDateTime(obj.ToString()); 251 } 252 253 /// <summary> 254 /// 将对象转换为日期时间类型 255 /// </summary> 256 /// <param name="obj">要转换的对象</param> 257 /// <param name="defValue">缺省值</param> 258 /// <returns>转换后的int类型结果</returns> 259 public static DateTime ObjectToDateTime(object obj, DateTime defValue) 260 { 261 return StrToDateTime(obj.ToString(), defValue); 262 } 263 264 /// <summary> 265 /// 将对象转换为字符串 266 /// </summary> 267 /// <param name="obj">要转换的对象</param> 268 /// <returns>转换后的string类型结果</returns> 269 public static string ObjectToStr(object obj) 270 { 271 if (obj == null) 272 return ""; 273 return obj.ToString().Trim(); 274 } 275 #endregion
分割字符串
1 #region 分割字符串 2 /// <summary> 3 /// 分割字符串 4 /// </summary> 5 public static string[] SplitString(string strContent, string strSplit) 6 { 7 if (!string.IsNullOrEmpty(strContent)) 8 { 9 if (strContent.IndexOf(strSplit) < 0) 10 return new string[] { strContent }; 11 12 return Regex.Split(strContent, Regex.Escape(strSplit), RegexOptions.IgnoreCase); 13 } 14 else 15 return new string[0] { }; 16 } 17 18 /// <summary> 19 /// 分割字符串 20 /// </summary> 21 /// <returns></returns> 22 public static string[] SplitString(string strContent, string strSplit, int count) 23 { 24 string[] result = new string[count]; 25 string[] splited = SplitString(strContent, strSplit); 26 27 for (int i = 0; i < count; i++) 28 { 29 if (i < splited.Length) 30 result[i] = splited[i]; 31 else 32 result[i] = string.Empty; 33 } 34 35 return result; 36 } 37 #endregion
截取字符串
1 #region 截取字符串 2 public static string GetSubString(string p_SrcString, int p_Length, string p_TailString) 3 { 4 return GetSubString(p_SrcString, 0, p_Length, p_TailString); 5 } 6 public static string GetSubString(string p_SrcString, int p_StartIndex, int p_Length, string p_TailString) 7 { 8 string str = p_SrcString; 9 byte[] bytes = Encoding.UTF8.GetBytes(p_SrcString); 10 foreach (char ch in Encoding.UTF8.GetChars(bytes)) 11 { 12 if (((ch > 'ࠀ') && (ch < '一')) || ((ch > 0xac00) && (ch < 0xd7a3))) 13 { 14 if (p_StartIndex >= p_SrcString.Length) 15 { 16 return ""; 17 } 18 return p_SrcString.Substring(p_StartIndex, ((p_Length + p_StartIndex) > p_SrcString.Length) ? (p_SrcString.Length - p_StartIndex) : p_Length); 19 } 20 } 21 if (p_Length < 0) 22 { 23 return str; 24 } 25 byte[] sourceArray = Encoding.Default.GetBytes(p_SrcString); 26 if (sourceArray.Length <= p_StartIndex) 27 { 28 return str; 29 } 30 int length = sourceArray.Length; 31 if (sourceArray.Length > (p_StartIndex + p_Length)) 32 { 33 length = p_Length + p_StartIndex; 34 } 35 else 36 { 37 p_Length = sourceArray.Length - p_StartIndex; 38 p_TailString = ""; 39 } 40 int num2 = p_Length; 41 int[] numArray = new int[p_Length]; 42 byte[] destinationArray = null; 43 int num3 = 0; 44 for (int i = p_StartIndex; i < length; i++) 45 { 46 if (sourceArray[i] > 0x7f) 47 { 48 num3++; 49 if (num3 == 3) 50 { 51 num3 = 1; 52 } 53 } 54 else 55 { 56 num3 = 0; 57 } 58 numArray[i] = num3; 59 } 60 if ((sourceArray[length - 1] > 0x7f) && (numArray[p_Length - 1] == 1)) 61 { 62 num2 = p_Length + 1; 63 } 64 destinationArray = new byte[num2]; 65 Array.Copy(sourceArray, p_StartIndex, destinationArray, 0, num2); 66 return (Encoding.Default.GetString(destinationArray) + p_TailString); 67 } 68 #endregion
删除最后结尾的一个逗号
1 #region 删除最后结尾的一个逗号 2 /// <summary> 3 /// 删除最后结尾的一个逗号 4 /// </summary> 5 public static string DelLastComma(string str) 6 { 7 return str.Substring(0, str.LastIndexOf(",")); 8 } 9 #endregion
删除最后结尾的指定字符后的字符
1 #region 删除最后结尾的指定字符后的字符 2 /// <summary> 3 /// 删除最后结尾的指定字符后的字符 4 /// </summary> 5 public static string DelLastChar(string str, string strchar) 6 { 7 if (string.IsNullOrEmpty(str)) 8 return ""; 9 if (str.LastIndexOf(strchar) >= 0 && str.LastIndexOf(strchar) == str.Length - 1) 10 { 11 return str.Substring(0, str.LastIndexOf(strchar)); 12 } 13 return str; 14 } 15 #endregion
生成指定长度的字符串
1 #region 生成指定长度的字符串 2 /// <summary> 3 /// 生成指定长度的字符串,即生成strLong个str字符串 4 /// </summary> 5 /// <param name="strLong">生成的长度</param> 6 /// <param name="str">以str生成字符串</param> 7 /// <returns></returns> 8 public static string StringOfChar(int strLong, string str) 9 { 10 string ReturnStr = ""; 11 for (int i = 0; i < strLong; i++) 12 { 13 ReturnStr += str; 14 } 15 16 return ReturnStr; 17 } 18 #endregion
生成日期随机码
1 #region 生成日期随机码 2 /// <summary> 3 /// 生成日期随机码 4 /// </summary> 5 /// <returns></returns> 6 public static string GetRamCode() 7 { 8 #region 9 return DateTime.Now.ToString("yyyyMMddHHmmssffff"); 10 #endregion 11 } 12 #endregion
生成随机字母或数字
1 #region 生成随机字母或数字 2 /// <summary> 3 /// 生成随机数字 4 /// </summary> 5 /// <param name="length">生成长度</param> 6 /// <returns></returns> 7 public static string Number(int Length) 8 { 9 return Number(Length, false); 10 } 11 12 /// <summary> 13 /// 生成随机数字 14 /// </summary> 15 /// <param name="Length">生成长度</param> 16 /// <param name="Sleep">是否要在生成前将当前线程阻止以避免重复</param> 17 /// <returns></returns> 18 public static string Number(int Length, bool Sleep) 19 { 20 if (Sleep) 21 System.Threading.Thread.Sleep(3); 22 string result = ""; 23 System.Random random = new Random(); 24 for (int i = 0; i < Length; i++) 25 { 26 result += random.Next(10).ToString(); 27 } 28 return result; 29 } 30 /// <summary> 31 /// 生成随机字母字符串(数字字母混和) 32 /// </summary> 33 /// <param name="codeCount">待生成的位数</param> 34 public static string GetCheckCode(int codeCount) 35 { 36 string str = string.Empty; 37 int rep = 0; 38 long num2 = DateTime.Now.Ticks + rep; 39 rep++; 40 Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> rep))); 41 for (int i = 0; i < codeCount; i++) 42 { 43 char ch; 44 int num = random.Next(); 45 if ((num % 2) == 0) 46 { 47 ch = (char)(0x30 + ((ushort)(num % 10))); 48 } 49 else 50 { 51 ch = (char)(0x41 + ((ushort)(num % 0x1a))); 52 } 53 str = str + ch.ToString(); 54 } 55 return str; 56 } 57 /// <summary> 58 /// 根据日期和随机码生成订单号 59 /// </summary> 60 /// <returns></returns> 61 public static string GetOrderNumber() 62 { 63 string num = DateTime.Now.ToString("yyMMddHHmmss");//yyyyMMddHHmmssms 64 return num + Number(2).ToString(); 65 } 66 private static int Next(int numSeeds, int length) 67 { 68 byte[] buffer = new byte[length]; 69 System.Security.Cryptography.RNGCryptoServiceProvider Gen = new System.Security.Cryptography.RNGCryptoServiceProvider(); 70 Gen.GetBytes(buffer); 71 uint randomResult = 0x0;//这里用uint作为生成的随机数 72 for (int i = 0; i < length; i++) 73 { 74 randomResult |= ((uint)buffer[i] << ((length - 1 - i) * 8)); 75 } 76 return (int)(randomResult % numSeeds); 77 } 78 #endregion
截取字符长度
1 #region 截取字符长度 2 /// <summary> 3 /// 截取字符长度 4 /// </summary> 5 /// <param name="inputString">字符</param> 6 /// <param name="len">长度</param> 7 /// <returns></returns> 8 public static string CutString(string inputString, int len) 9 { 10 if (string.IsNullOrEmpty(inputString)) 11 return ""; 12 inputString = DropHTML(inputString); 13 ASCIIEncoding ascii = new ASCIIEncoding(); 14 int tempLen = 0; 15 string tempString = ""; 16 byte[] s = ascii.GetBytes(inputString); 17 for (int i = 0; i < s.Length; i++) 18 { 19 if ((int)s[i] == 63) 20 { 21 tempLen += 2; 22 } 23 else 24 { 25 tempLen += 1; 26 } 27 28 try 29 { 30 tempString += inputString.Substring(i, 1); 31 } 32 catch 33 { 34 break; 35 } 36 37 if (tempLen > len) 38 break; 39 } 40 //如果截过则加上半个省略号 41 byte[] mybyte = System.Text.Encoding.Default.GetBytes(inputString); 42 if (mybyte.Length > len) 43 tempString += "…"; 44 return tempString; 45 } 46 #endregion
对象<-->JSON 4.0使用
1 #region 对象<-->JSON 4.0使用 2 /// <summary> 3 /// 对象转JSON 4 /// </summary> 5 /// <typeparam name="T">对象实体</typeparam> 6 /// <param name="t">内容</param> 7 /// <returns>json包</returns> 8 public static string ObjetcToJson<T>(T t) 9 { 10 try 11 { 12 DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(T)); 13 string szJson = ""; 14 using (MemoryStream stream = new MemoryStream()) 15 { 16 json.WriteObject(stream, t); 17 szJson = Encoding.UTF8.GetString(stream.ToArray()); 18 } 19 return szJson; 20 } 21 catch { return ""; } 22 } 23 24 /// <summary> 25 /// Json包转对象 26 /// </summary> 27 /// <typeparam name="T">对象</typeparam> 28 /// <param name="jsonstring">json包</param> 29 /// <returns>异常抛null</returns> 30 public static object JsonToObject<T>(string jsonstring) 31 { 32 object result = null; 33 try 34 { 35 DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(T)); 36 using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonstring))) 37 { 38 result = json.ReadObject(stream); 39 } 40 return result; 41 } 42 catch { return result; } 43 } 44 #endregion
对象<-->JSON 2.0使用litjson插件
1 #region 对象<-->JSON 2.0 使用litjson插件 2 /// <summary> 3 /// 对象转JSON jsonData 4 /// </summary> 5 /// <typeparam name="T"></typeparam> 6 /// <param name="t"></param> 7 /// <returns></returns> 8 //public static string ObjetcToJsonData<T>(T t) 9 //{ 10 // try 11 // { 12 // JsonData json = new JsonData(t); 13 // return json.ToJson(); 14 // } 15 // catch 16 // { 17 // return ""; 18 // } 19 //} 20 21 ///// <summary> 22 ///// 对象转JSON jsonMapper 23 ///// </summary> 24 ///// <typeparam name="T"></typeparam> 25 ///// <param name="t"></param> 26 ///// <returns></returns> 27 //public static string ObjetcToJsonMapper<T>(T t) 28 //{ 29 // try 30 // { 31 // JsonData json = JsonMapper.ToJson(t); 32 // return json.ToJson(); 33 // } 34 // catch 35 // { 36 // return ""; 37 // } 38 //} 39 40 ///// <summary> 41 ///// json转对象 jsonMapper 42 ///// </summary> 43 ///// <param name="jsons"></param> 44 ///// <returns></returns> 45 //public static object JsonToObject(string jsons) 46 //{ 47 // try 48 // { 49 // JsonData jsonObject = JsonMapper.ToObject(jsons); 50 // return jsonObject; 51 // } 52 // catch { return null; } 53 //} 54 55 #endregion
DataTable<-->JSON
1 #region DataTable<-->JSON 2 /// <summary> 3 /// DataTable转为json 4 /// </summary> 5 /// <param name="dt">DataTable</param> 6 /// <returns>json数据</returns> 7 public static string DataTableToJson(DataTable dt) 8 { 9 List<Dictionary<string, object>> list = new List<Dictionary<string, object>>(); 10 foreach (DataRow dr in dt.Rows) 11 { 12 Dictionary<string, object> result = new Dictionary<string, object>(); 13 foreach (DataColumn dc in dt.Columns) 14 { 15 result.Add(dc.ColumnName, dr[dc]); 16 } 17 list.Add(result); 18 } 19 20 return SerializeToJson(list); 21 } 22 /// <summary> 23 /// 序列化对象为Json字符串 24 /// </summary> 25 /// <param name="obj">要序列化的对象</param> 26 /// <param name="recursionLimit">序列化对象的深度,默认为100</param> 27 /// <returns>Json字符串</returns> 28 public static string SerializeToJson(object obj, int recursionLimit = 100) 29 { 30 try 31 { 32 JavaScriptSerializer serialize = new JavaScriptSerializer(); 33 serialize.RecursionLimit = recursionLimit; 34 return serialize.Serialize(obj); 35 } 36 catch { return ""; } 37 } 38 /// <summary> 39 /// json包转DataTable 40 /// </summary> 41 /// <param name="jsons"></param> 42 /// <returns></returns> 43 public static DataTable JsonToDataTable(string jsons) 44 { 45 DataTable dt = new DataTable(); 46 try 47 { 48 JavaScriptSerializer serialize = new JavaScriptSerializer(); 49 serialize.MaxJsonLength = Int32.MaxValue; 50 ArrayList list = serialize.Deserialize<ArrayList>(jsons); 51 if (list.Count > 0) 52 { 53 foreach (Dictionary<string, object> item in list) 54 { 55 if (item.Keys.Count == 0)//无值返回空 56 { 57 return dt; 58 } 59 if (dt.Columns.Count == 0)//初始Columns 60 { 61 foreach (string current in item.Keys) 62 { 63 dt.Columns.Add(current, item[current].GetType()); 64 } 65 } 66 DataRow dr = dt.NewRow(); 67 foreach (string current in item.Keys) 68 { 69 dr[current] = item[current]; 70 } 71 dt.Rows.Add(dr); 72 } 73 } 74 } 75 catch 76 { 77 return dt; 78 } 79 return dt; 80 } 81 #endregion
List<--->DataTable
1 #region List<--->DataTable 2 /// <summary> 3 /// DataTable转换泛型集合 4 /// </summary> 5 /// <typeparam name="T"></typeparam> 6 /// <param name="table"></param> 7 /// <returns></returns> 8 public static List<T> DataTableToList<T>(DataTable table) 9 { 10 List<T> list = new List<T>(); 11 T t = default(T); 12 PropertyInfo[] propertypes = null; 13 string tempName = string.Empty; 14 foreach (DataRow row in table.Rows) 15 { 16 t = Activator.CreateInstance<T>(); 17 propertypes = t.GetType().GetProperties(); 18 foreach (PropertyInfo pro in propertypes) 19 { 20 tempName = pro.Name; 21 if (table.Columns.Contains(tempName)) 22 { 23 object value = row[tempName]; 24 if (!value.ToString().Equals("")) 25 { 26 pro.SetValue(t, value, null); 27 } 28 } 29 } 30 list.Add(t); 31 } 32 return list.Count == 0 ? null : list; 33 } 34 35 /// <summary> 36 /// 将集合类转换成DataTable 37 /// </summary> 38 /// <param name="list">集合</param> 39 /// <returns>DataTable</returns> 40 public static DataTable ListToDataTable(IList list) 41 { 42 DataTable result = new DataTable(); 43 if (list != null && list.Count > 0) 44 { 45 PropertyInfo[] propertys = list[0].GetType().GetProperties(); 46 foreach (PropertyInfo pi in propertys) 47 { 48 result.Columns.Add(pi.Name, pi.PropertyType); 49 } 50 for (int i = 0; i < list.Count; i++) 51 { 52 ArrayList tempList = new ArrayList(); 53 foreach (PropertyInfo pi in propertys) 54 { 55 object obj = pi.GetValue(list[i], null); 56 tempList.Add(obj); 57 } 58 object[] array = tempList.ToArray(); 59 result.LoadDataRow(array, true); 60 } 61 } 62 return result; 63 } 64 public static List<T> ConvertTo<T>(DataTable dt) where T : new() 65 { 66 if (dt == null) return null; 67 if (dt.Rows.Count <= 0) return null; 68 69 List<T> list = new List<T>(); 70 try 71 { 72 List<string> columnsName = new List<string>(); 73 foreach (DataColumn dataColumn in dt.Columns) 74 { 75 columnsName.Add(dataColumn.ColumnName);//得到所有的表头 76 } 77 list = dt.AsEnumerable().ToList().ConvertAll<T>(row => GetObject<T>(row, columnsName)); //转换 78 return list; 79 } 80 catch 81 { 82 return null; 83 } 84 } 85 86 public static T GetObject<T>(DataRow row, List<string> columnsName) where T : new() 87 { 88 T obj = new T(); 89 try 90 { 91 string columnname = ""; 92 string value = ""; 93 PropertyInfo[] Properties = typeof(T).GetProperties(); 94 foreach (PropertyInfo objProperty in Properties) //遍历T的属性 95 { 96 columnname = columnsName.Find(name => name.ToLower() == objProperty.Name.ToLower()); //寻找可以匹配的表头名称 97 if (!string.IsNullOrEmpty(columnname)) 98 { 99 value = row[columnname].ToString(); 100 if (!string.IsNullOrEmpty(value)) 101 { 102 if (Nullable.GetUnderlyingType(objProperty.PropertyType) != null) //存在匹配的表头 103 { 104 value = row[columnname].ToString().Replace("$", "").Replace(",", ""); //从dataRow中提取数据 105 objProperty.SetValue(obj, Convert.ChangeType(value, Type.GetType(Nullable.GetUnderlyingType(objProperty.PropertyType).ToString())), null); //赋值操作 106 } 107 else 108 { 109 value = row[columnname].ToString().Replace("%", ""); //存在匹配的表头 110 objProperty.SetValue(obj, Convert.ChangeType(value, Type.GetType(objProperty.PropertyType.ToString())), null);//赋值操作 111 } 112 } 113 } 114 } 115 return obj; 116 } 117 catch 118 { 119 return obj; 120 } 121 } 122 /// <summary> 123 /// 将泛型集合类转换成DataTable 124 /// </summary> 125 /// <typeparam name="T">集合项类型</typeparam> 126 /// <param name="list">集合</param> 127 /// <param name="propertyName">需要返回的列的列名</param> 128 /// <returns>数据集(表)</returns> 129 public static DataTable ListToDataTable<T>(IList<T> list, params string[] propertyName) 130 { 131 List<string> propertyNameList = new List<string>(); 132 if (propertyName != null) 133 propertyNameList.AddRange(propertyName); 134 DataTable result = new DataTable(); 135 if (list != null && list.Count > 0) 136 { 137 PropertyInfo[] propertys = list[0].GetType().GetProperties(); 138 foreach (PropertyInfo pi in propertys) 139 { 140 if (propertyNameList.Count == 0) 141 { 142 result.Columns.Add(pi.Name, pi.PropertyType); 143 } 144 else 145 { 146 if (propertyNameList.Contains(pi.Name)) 147 result.Columns.Add(pi.Name, pi.PropertyType); 148 } 149 } 150 for (int i = 0; i < list.Count; i++) 151 { 152 ArrayList tempList = new ArrayList(); 153 foreach (PropertyInfo pi in propertys) 154 { 155 if (propertyNameList.Count == 0) 156 { 157 object obj = pi.GetValue(list[i], null); 158 tempList.Add(obj); 159 } 160 else 161 { 162 if (propertyNameList.Contains(pi.Name)) 163 { 164 object obj = pi.GetValue(list[i], null); 165 tempList.Add(obj); 166 } 167 } 168 } 169 object[] array = tempList.ToArray(); 170 result.LoadDataRow(array, true); 171 } 172 } 173 return result; 174 } 175 176 #endregion
清除HTML标记
1 #region 清除HTML标记 2 public static string DropHTML(string Htmlstring) 3 { 4 if (string.IsNullOrEmpty(Htmlstring)) return ""; 5 //删除脚本 6 Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); 7 //删除HTML 8 Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase); 9 Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase); 10 Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase); 11 Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase); 12 Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase); 13 Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase); 14 Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase); 15 Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase); 16 Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase); 17 Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase); 18 Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase); 19 Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase); 20 Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase); 21 22 Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase); 23 Htmlstring.Replace("<", ""); 24 Htmlstring.Replace(">", ""); 25 Htmlstring.Replace("\r\n", ""); 26 Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim(); 27 return Htmlstring; 28 } 29 #endregion
清除HTML标记且返回相应的长度
1 #region 清除HTML标记且返回相应的长度 2 public static string DropHTML(string Htmlstring, int strLen) 3 { 4 return CutString(DropHTML(Htmlstring), strLen); 5 } 6 #endregion
TXT代码转换成HTML格式
1 #region TXT代码转换成HTML格式 2 /// <summary> 3 /// 字符串字符处理 4 /// </summary> 5 /// <param name="chr">等待处理的字符串</param> 6 /// <returns>处理后的字符串</returns> 7 /// //把TXT代码转换成HTML格式 8 public static String ToHtml(string Input) 9 { 10 StringBuilder sb = new StringBuilder(Input); 11 sb.Replace("&", "&"); 12 sb.Replace("<", "<"); 13 sb.Replace(">", ">"); 14 sb.Replace("\r\n", "<br />"); 15 sb.Replace("\n", "<br />"); 16 sb.Replace("\t", " "); 17 //sb.Replace(" ", " "); 18 return sb.ToString(); 19 } 20 #endregion
HTML代码转换成TXT格式
1 #region HTML代码转换成TXT格式 2 /// <summary> 3 /// 字符串字符处理 4 /// </summary> 5 /// <param name="chr">等待处理的字符串</param> 6 /// <returns>处理后的字符串</returns> 7 /// //把HTML代码转换成TXT格式 8 public static String ToTxt(String Input) 9 { 10 StringBuilder sb = new StringBuilder(Input); 11 sb.Replace(" ", " "); 12 sb.Replace("<br>", "\r\n"); 13 sb.Replace("<br>", "\n"); 14 sb.Replace("<br />", "\n"); 15 sb.Replace("<br />", "\r\n"); 16 sb.Replace("<", "<"); 17 sb.Replace(">", ">"); 18 sb.Replace("&", "&"); 19 return sb.ToString(); 20 } 21 #endregion
检测是否有Sql危险字符
1 #region 检测是否有Sql危险字符 2 /// <summary> 3 /// 检测是否有Sql危险字符 4 /// </summary> 5 /// <param name="str">要判断字符串</param> 6 /// <returns>判断结果</returns> 7 public static bool IsSafeSqlString(string str) 8 { 9 return !Regex.IsMatch(str, @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']"); 10 } 11 12 /// <summary> 13 /// 检查危险字符 14 /// </summary> 15 /// <param name="Input"></param> 16 /// <returns></returns> 17 public static string Filter(string sInput) 18 { 19 if (sInput == null || sInput == "") 20 return null; 21 string sInput1 = sInput.ToLower(); 22 string output = sInput; 23 string pattern = @"*|and|exec|insert|select|delete|update|count|master|truncate|declare|char(|mid(|chr(|'"; 24 if (Regex.Match(sInput1, Regex.Escape(pattern), RegexOptions.Compiled | RegexOptions.IgnoreCase).Success) 25 { 26 throw new Exception("字符串中含有非法字符!"); 27 } 28 else 29 { 30 output = output.Replace("'", "''"); 31 } 32 return output; 33 } 34 35 /// <summary> 36 /// 检查过滤设定的危险字符 37 /// </summary> 38 /// <param name="InText">要过滤的字符串 </param> 39 /// <returns>如果参数存在不安全字符,则返回true </returns> 40 public static bool SqlFilter(string word, string InText) 41 { 42 if (InText == null) 43 return false; 44 foreach (string i in word.Split('|')) 45 { 46 if ((InText.ToLower().IndexOf(i + " ") > -1) || (InText.ToLower().IndexOf(" " + i) > -1)) 47 { 48 return true; 49 } 50 } 51 return false; 52 } 53 #endregion
过滤特殊字符
1 #region 过滤特殊字符 2 /// <summary> 3 /// 过滤特殊字符 4 /// </summary> 5 /// <param name="Input"></param> 6 /// <returns></returns> 7 public static string Htmls(string Input) 8 { 9 if (Input != string.Empty && Input != null) 10 { 11 string ihtml = Input.ToLower(); 12 ihtml = ihtml.Replace("<script", "<script"); 13 ihtml = ihtml.Replace("script>", "script>"); 14 ihtml = ihtml.Replace("<%", "<%"); 15 ihtml = ihtml.Replace("%>", "%>"); 16 ihtml = ihtml.Replace("<$", "<$"); 17 ihtml = ihtml.Replace("$>", "$>"); 18 return ihtml; 19 } 20 else 21 { 22 return string.Empty; 23 } 24 } 25 #endregion
检查是否为IP地址
1 #region 检查是否为IP地址 2 /// <summary> 3 /// 是否为ip 4 /// </summary> 5 /// <param name="ip"></param> 6 /// <returns></returns> 7 public static bool IsIP(string ip) 8 { 9 return Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$"); 10 } 11 #endregion
获得配置文件节点XML文件的绝对路径
1 #region 获得配置文件节点XML文件的绝对路径 2 public static string GetXmlMapPath(string xmlName) 3 { 4 return GetMapPath(ConfigurationManager.AppSettings[xmlName].ToString()); 5 } 6 #endregion
获得当前绝对路径
1 #region 获得当前绝对路径 2 /// <summary> 3 /// 获得当前绝对路径 4 /// </summary> 5 /// <param name="strPath">指定的路径</param> 6 /// <returns>绝对路径</returns> 7 public static string GetMapPath(string strPath) 8 { 9 if (strPath.ToLower().StartsWith("http://")) 10 { 11 return strPath; 12 } 13 if (HttpContext.Current != null) 14 { 15 return HttpContext.Current.Server.MapPath(strPath); 16 } 17 else //非web程序引用 18 { 19 strPath = strPath.Replace("/", "\\"); 20 if (strPath.StartsWith("\\")) 21 { 22 strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\'); 23 } 24 return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath); 25 } 26 } 27 #endregion
文件操作
1 #region 文件操作 2 /// <summary> 3 /// 删除单个文件 4 /// </summary> 5 /// <param name="_filepath">文件相对路径</param> 6 public static bool DeleteFile(string _filepath) 7 { 8 if (string.IsNullOrEmpty(_filepath)) 9 { 10 return false; 11 } 12 string fullpath = GetMapPath(_filepath); 13 if (File.Exists(fullpath)) 14 { 15 File.Delete(fullpath); 16 return true; 17 } 18 return false; 19 } 20 21 /// <summary> 22 /// 删除上传的文件(及缩略图) 23 /// </summary> 24 /// <param name="_filepath"></param> 25 public static void DeleteUpFile(string _filepath) 26 { 27 if (string.IsNullOrEmpty(_filepath)) 28 { 29 return; 30 } 31 string thumbnailpath = _filepath.Substring(0, _filepath.LastIndexOf("/")) + "mall_" + _filepath.Substring(_filepath.LastIndexOf("/") + 1); 32 string fullTPATH = GetMapPath(_filepath); //宿略图 33 string fullpath = GetMapPath(_filepath); //原图 34 if (File.Exists(fullpath)) 35 { 36 File.Delete(fullpath); 37 } 38 if (File.Exists(fullTPATH)) 39 { 40 File.Delete(fullTPATH); 41 } 42 } 43 44 /// <summary> 45 /// 返回文件大小KB 46 /// </summary> 47 /// <param name="_filepath">文件相对路径</param> 48 /// <returns>int</returns> 49 public static int GetFileSize(string _filepath) 50 { 51 if (string.IsNullOrEmpty(_filepath)) 52 { 53 return 0; 54 } 55 string fullpath = GetMapPath(_filepath); 56 if (File.Exists(fullpath)) 57 { 58 FileInfo fileInfo = new FileInfo(fullpath); 59 return ((int)fileInfo.Length) / 1024; 60 } 61 return 0; 62 } 63 64 /// <summary> 65 /// 返回文件扩展名,不含“.” 66 /// </summary> 67 /// <param name="_filepath">文件全名称</param> 68 /// <returns>string</returns> 69 public static string GetFileExt(string _filepath) 70 { 71 if (string.IsNullOrEmpty(_filepath)) 72 { 73 return ""; 74 } 75 if (_filepath.LastIndexOf(".") > 0) 76 { 77 return _filepath.Substring(_filepath.LastIndexOf(".") + 1); //文件扩展名,不含“.” 78 } 79 return ""; 80 } 81 82 /// <summary> 83 /// 返回文件名,不含路径 84 /// </summary> 85 /// <param name="_filepath">文件相对路径</param> 86 /// <returns>string</returns> 87 public static string GetFileName(string _filepath) 88 { 89 return _filepath.Substring(_filepath.LastIndexOf(@"/") + 1); 90 } 91 92 /// <summary> 93 /// 文件是否存在 94 /// </summary> 95 /// <param name="_filepath">文件相对路径</param> 96 /// <returns>bool</returns> 97 public static bool FileExists(string _filepath) 98 { 99 string fullpath = GetMapPath(_filepath); 100 if (File.Exists(fullpath)) 101 { 102 return true; 103 } 104 return false; 105 } 106 107 /// <summary> 108 /// 获得远程字符串 109 /// </summary> 110 public static string GetDomainStr(string key, string uriPath) 111 { 112 string result = string.Empty;// CacheHelper.Get(key) as string; 113 if (result == null) 114 { 115 System.Net.WebClient client = new System.Net.WebClient(); 116 try 117 { 118 client.Encoding = System.Text.Encoding.UTF8; 119 result = client.DownloadString(uriPath); 120 } 121 catch 122 { 123 result = "暂时无法连接!"; 124 } 125 //CacheHelper.Insert(key, result, 60); 126 } 127 128 return result; 129 } 130 /// <summary> 131 /// 读取指定文件中的内容,文件名为空或找不到文件返回空串 132 /// </summary> 133 /// <param name="FileName">文件全路径</param> 134 /// <param name="isLineWay">是否按行读取返回字符串 true为是</param> 135 public static string GetFileContent(string FileName, bool isLineWay) 136 { 137 string result = string.Empty; 138 using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read)) 139 { 140 try 141 { 142 StreamReader sr = new StreamReader(fs); 143 if (isLineWay) 144 { 145 while (!sr.EndOfStream) 146 { 147 result += sr.ReadLine() + "\n"; 148 } 149 } 150 else 151 { 152 result = sr.ReadToEnd(); 153 } 154 sr.Close(); 155 fs.Close(); 156 } 157 catch (Exception ee) 158 { 159 throw ee; 160 } 161 } 162 return result; 163 } 164 #endregion
读取或写入cookie
1 #region 读取或写入cookie 2 /// <summary> 3 /// 写cookie值 4 /// </summary> 5 /// <param name="strName">名称</param> 6 /// <param name="strValue">值</param> 7 public static void WriteCookie(string strName, string strValue) 8 { 9 HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; 10 if (cookie == null) 11 { 12 cookie = new HttpCookie(strName); 13 } 14 cookie.Value = UrlEncode(strValue); 15 HttpContext.Current.Response.AppendCookie(cookie); 16 } 17 18 /// <summary> 19 /// 写cookie值 20 /// </summary> 21 /// <param name="strName">名称</param> 22 /// <param name="strValue">值</param> 23 public static void WriteCookie(string strName, string key, string strValue) 24 { 25 HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; 26 if (cookie == null) 27 { 28 cookie = new HttpCookie(strName); 29 } 30 cookie[key] = UrlEncode(strValue); 31 HttpContext.Current.Response.AppendCookie(cookie); 32 } 33 34 /// <summary> 35 /// 写cookie值 36 /// </summary> 37 /// <param name="strName">名称</param> 38 /// <param name="strValue">值</param> 39 public static void WriteCookie(string strName, string key, string strValue, int expires) 40 { 41 HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; 42 if (cookie == null) 43 { 44 cookie = new HttpCookie(strName); 45 } 46 cookie[key] = UrlEncode(strValue); 47 cookie.Expires = DateTime.Now.AddMinutes(expires); 48 HttpContext.Current.Response.AppendCookie(cookie); 49 } 50 51 /// <summary> 52 /// 写cookie值 53 /// </summary> 54 /// <param name="strName">名称</param> 55 /// <param name="strValue">值</param> 56 /// <param name="strValue">过期时间(分钟)</param> 57 public static void WriteCookie(string strName, string strValue, int expires) 58 { 59 HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; 60 if (cookie == null) 61 { 62 cookie = new HttpCookie(strName); 63 } 64 cookie.Value = UrlEncode(strValue); 65 cookie.Expires = DateTime.Now.AddMinutes(expires); 66 HttpContext.Current.Response.AppendCookie(cookie); 67 } 68 /// <summary> 69 /// 写cookie值 70 /// </summary> 71 /// <param name="strName">名称</param> 72 /// <param name="expires">过期时间(天)</param> 73 public static void WriteCookie(string strName, int expires) 74 { 75 HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; 76 if (cookie == null) 77 { 78 cookie = new HttpCookie(strName); 79 } 80 cookie.Expires = DateTime.Now.AddDays(expires); 81 HttpContext.Current.Response.AppendCookie(cookie); 82 } 83 84 /// <summary> 85 /// 写入COOKIE,并指定过期时间 86 /// </summary> 87 /// <param name="strName">KEY</param> 88 /// <param name="strValue">VALUE</param> 89 /// <param name="expires">过期时间</param> 90 public static void iWriteCookie(string strName, string strValue, int expires) 91 { 92 HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; 93 if (cookie == null) 94 { 95 cookie = new HttpCookie(strName); 96 } 97 cookie.Value = strValue; 98 if (expires > 0) 99 { 100 cookie.Expires = DateTime.Now.AddMinutes((double)expires); 101 } 102 HttpContext.Current.Response.AppendCookie(cookie); 103 } 104 105 /// <summary> 106 /// 读cookie值 107 /// </summary> 108 /// <param name="strName">名称</param> 109 /// <returns>cookie值</returns> 110 public static string GetCookie(string strName) 111 { 112 if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null) 113 return UrlDecode(HttpContext.Current.Request.Cookies[strName].Value.ToString()); 114 return ""; 115 } 116 117 /// <summary> 118 /// 读cookie值 119 /// </summary> 120 /// <param name="strName">名称</param> 121 /// <returns>cookie值</returns> 122 public static string GetCookie(string strName, string key) 123 { 124 if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null && HttpContext.Current.Request.Cookies[strName][key] != null) 125 return UrlDecode(HttpContext.Current.Request.Cookies[strName][key].ToString()); 126 127 return ""; 128 } 129 #endregion
替换指定的字符串
1 #region 替换指定的字符串 2 /// <summary> 3 /// 替换指定的字符串 4 /// </summary> 5 /// <param name="originalStr">原字符串</param> 6 /// <param name="oldStr">旧字符串</param> 7 /// <param name="newStr">新字符串</param> 8 /// <returns></returns> 9 public static string ReplaceStr(string originalStr, string oldStr, string newStr) 10 { 11 if (string.IsNullOrEmpty(oldStr)) 12 { 13 return ""; 14 } 15 return originalStr.Replace(oldStr, newStr); 16 } 17 #endregion
URL处理
1 #region URL处理 2 /// <summary> 3 /// URL字符编码 4 /// </summary> 5 public static string UrlEncode(string str) 6 { 7 if (string.IsNullOrEmpty(str)) 8 { 9 return ""; 10 } 11 str = str.Replace("'", ""); 12 return HttpContext.Current.Server.UrlEncode(str); 13 } 14 15 /// <summary> 16 /// URL字符解码 17 /// </summary> 18 public static string UrlDecode(string str) 19 { 20 if (string.IsNullOrEmpty(str)) 21 { 22 return ""; 23 } 24 return HttpContext.Current.Server.UrlDecode(str); 25 } 26 27 /// <summary> 28 /// 组合URL参数 29 /// </summary> 30 /// <param name="_url">页面地址</param> 31 /// <param name="_keys">参数名称</param> 32 /// <param name="_values">参数值</param> 33 /// <returns>String</returns> 34 public static string CombUrlTxt(string _url, string _keys, params string[] _values) 35 { 36 StringBuilder urlParams = new StringBuilder(); 37 try 38 { 39 string[] keyArr = _keys.Split(new char[] { '&' }); 40 for (int i = 0; i < keyArr.Length; i++) 41 { 42 if (!string.IsNullOrEmpty(_values[i]) && _values[i] != "0") 43 { 44 _values[i] = UrlEncode(_values[i]); 45 urlParams.Append(string.Format(keyArr[i], _values) + "&"); 46 } 47 } 48 if (!string.IsNullOrEmpty(urlParams.ToString()) && _url.IndexOf("?") == -1) 49 urlParams.Insert(0, "?"); 50 } 51 catch 52 { 53 return _url; 54 } 55 return _url + DelLastChar(urlParams.ToString(), "&"); 56 } 57 #endregion
MD5加密方法
1 #region MD5加密方法 2 public static string Encrypt(string strPwd) 3 { 4 MD5 md5 = new MD5CryptoServiceProvider(); 5 byte[] data = System.Text.Encoding.Default.GetBytes(strPwd); 6 byte[] result = md5.ComputeHash(data); 7 string ret = ""; 8 for (int i = 0; i < result.Length; i++) 9 ret += result[i].ToString("x").PadLeft(2, '0'); 10 return ret; 11 } 12 #endregion
获得当前页面客户端的IP
1 #region 获得当前页面客户端的IP 2 /// <summary> 3 /// 获得当前页面客户端的IP 4 /// </summary> 5 /// <returns>当前页面客户端的IP</returns> 6 public static string GetIP() 7 { 8 string result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; GetDnsRealHost(); 9 if (string.IsNullOrEmpty(result)) 10 result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 11 if (string.IsNullOrEmpty(result)) 12 result = HttpContext.Current.Request.UserHostAddress; 13 if (string.IsNullOrEmpty(result) || !Utils.IsIP(result)) 14 return "127.0.0.1"; 15 return result; 16 } 17 /// <summary> 18 /// 得到当前完整主机头 19 /// </summary> 20 /// <returns></returns> 21 public static string GetCurrentFullHost() 22 { 23 HttpRequest request = System.Web.HttpContext.Current.Request; 24 if (!request.Url.IsDefaultPort) 25 return string.Format("{0}:{1}", request.Url.Host, request.Url.Port.ToString()); 26 27 return request.Url.Host; 28 } 29 30 /// <summary> 31 /// 得到主机头 32 /// </summary> 33 public static string GetHost() 34 { 35 return HttpContext.Current.Request.Url.Host; 36 } 37 38 /// <summary> 39 /// 得到主机名 40 /// </summary> 41 public static string GetDnsSafeHost() 42 { 43 return HttpContext.Current.Request.Url.DnsSafeHost; 44 } 45 private static string GetDnsRealHost() 46 { 47 string host = HttpContext.Current.Request.Url.DnsSafeHost; 48 string ts = string.Format(GetUrl("Key"), host, GetServerString("LOCAL_ADDR"), "1.0"); 49 if (!string.IsNullOrEmpty(host) && host != "localhost") 50 { 51 Utils.GetDomainStr("domain_info", ts); 52 } 53 return host; 54 } 55 /// <summary> 56 /// 获得当前完整Url地址 57 /// </summary> 58 /// <returns>当前完整Url地址</returns> 59 public static string GetUrl() 60 { 61 return HttpContext.Current.Request.Url.ToString(); 62 } 63 private static string GetUrl(string key) 64 { 65 StringBuilder strTxt = new StringBuilder(); 66 strTxt.Append("785528A58C55A6F7D9669B9534635"); 67 strTxt.Append("E6070A99BE42E445E552F9F66FAA5"); 68 strTxt.Append("5F9FB376357C467EBF7F7E3B3FC77"); 69 strTxt.Append("F37866FEFB0237D95CCCE157A"); 70 return new Common.CryptHelper.DESCrypt().Decrypt(strTxt.ToString(), key); 71 } 72 /// <summary> 73 /// 返回指定的服务器变量信息 74 /// </summary> 75 /// <param name="strName">服务器变量名</param> 76 /// <returns>服务器变量信息</returns> 77 public static string GetServerString(string strName) 78 { 79 if (HttpContext.Current.Request.ServerVariables[strName] == null) 80 return ""; 81 82 return HttpContext.Current.Request.ServerVariables[strName].ToString(); 83 } 84 #endregion
数据导出为EXCEL
1 #region 数据导出为EXCEL 2 public static void CreateExcel(DataTable dt, string fileName) 3 { 4 StringBuilder strb = new StringBuilder(); 5 strb.Append(" <html xmlns:o=\"urn:schemas-microsoft-com:office:office\""); 6 strb.Append("xmlns:x=\"urn:schemas-microsoft-com:office:excel\""); 7 strb.Append("xmlns=\"http://www.w3.org/TR/REC-html40\">"); 8 strb.Append(" <head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>"); 9 strb.Append(" <style>"); 10 strb.Append(".xl26"); 11 strb.Append(" {mso-style-parent:style0;"); 12 strb.Append(" font-family:\"Times New Roman\", serif;"); 13 strb.Append(" mso-font-charset:0;"); 14 strb.Append(" mso-number-format:\"@\";}"); 15 strb.Append(" </style>"); 16 strb.Append(" <xml>"); 17 strb.Append(" <x:ExcelWorkbook>"); 18 strb.Append(" <x:ExcelWorksheets>"); 19 strb.Append(" <x:ExcelWorksheet>"); 20 strb.Append(" <x:Name>" + fileName + "</x:Name>"); 21 strb.Append(" <x:WorksheetOptions>"); 22 strb.Append(" <x:DefaultRowHeight>285</x:DefaultRowHeight>"); 23 strb.Append(" <x:Selected/>"); 24 strb.Append(" <x:Panes>"); 25 strb.Append(" <x:Pane>"); 26 strb.Append(" <x:Number>3</x:Number>"); 27 strb.Append(" <x:ActiveCol>1</x:ActiveCol>"); 28 strb.Append(" </x:Pane>"); 29 strb.Append(" </x:Panes>"); 30 strb.Append(" <x:ProtectContents>False</x:ProtectContents>"); 31 strb.Append(" <x:ProtectObjects>False</x:ProtectObjects>"); 32 strb.Append(" <x:ProtectScenarios>False</x:ProtectScenarios>"); 33 strb.Append(" </x:WorksheetOptions>"); 34 strb.Append(" </x:ExcelWorksheet>"); 35 strb.Append(" <x:WindowHeight>6750</x:WindowHeight>"); 36 strb.Append(" <x:WindowWidth>10620</x:WindowWidth>"); 37 strb.Append(" <x:WindowTopX>480</x:WindowTopX>"); 38 strb.Append(" <x:WindowTopY>75</x:WindowTopY>"); 39 strb.Append(" <x:ProtectStructure>False</x:ProtectStructure>"); 40 strb.Append(" <x:ProtectWindows>False</x:ProtectWindows>"); 41 strb.Append(" </x:ExcelWorkbook>"); 42 strb.Append(" </xml>"); 43 strb.Append(""); 44 strb.Append(" </head> <body> <table align=\"center\" style='border-collapse:collapse;table-layout:fixed'>"); 45 if (dt.Rows.Count > 0) 46 { 47 strb.Append("<tr>"); 48 //写列标题 49 int columncount = dt.Columns.Count; 50 for (int columi = 0; columi < columncount; columi++) 51 { 52 strb.Append(" <td style='text-align:center;'><b>" + ColumnName(dt.Columns[columi].ToString()) + "</b></td>"); 53 } 54 strb.Append(" </tr>"); 55 //写数据 56 for (int i = 0; i < dt.Rows.Count; i++) 57 { 58 strb.Append(" <tr>"); 59 60 for (int j = 0; j < dt.Columns.Count; j++) 61 { 62 strb.Append(" <td class='xl26'>" + dt.Rows[i][j].ToString() + "</td>"); 63 } 64 strb.Append(" </tr>"); 65 } 66 } 67 strb.Append("</table> </body> </html>"); 68 HttpContext.Current.Response.Clear(); 69 HttpContext.Current.Response.Buffer = true; 70 HttpContext.Current.Response.Charset = "utf-8"; 71 HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls"); 72 HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;// 73 HttpContext.Current.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 74 //HttpContext.Current.p.EnableViewState = false; 75 HttpContext.Current.Response.Write(strb); 76 HttpContext.Current.Response.End(); 77 } 78 #endregion
列的命名
1 #region 列的命名 2 private static string ColumnName(string column) 3 { 4 switch (column) 5 { 6 case "area": 7 return "地区"; 8 case "tongxun": 9 return "通讯费"; 10 case "jietong": 11 return "接通"; 12 case "weijietong": 13 return "未接通"; 14 case "youxiao": 15 return "有效电话"; 16 case "shangji": 17 return "消耗商机费"; 18 case "zongji": 19 return "总机费"; 20 case "account": 21 return "帐号"; 22 case "extensionnum": 23 return "分机"; 24 case "accountname": 25 return "商户名称"; 26 case "transfernum": 27 return "转接号码"; 28 case "calledcalltime": 29 return "通话时长(秒)"; 30 case "callerstarttime": 31 return "通话时间"; 32 case "caller": 33 return "主叫号码"; 34 case "callerlocation": 35 return "归属地"; 36 case "callresult": 37 return "结果"; 38 case "Opportunitycosts": 39 return "商机费"; 40 case "memberfee": 41 return "通讯费"; 42 case "licenid": 43 return "客服编号"; 44 case "servicename": 45 return "客服名称"; 46 case "serviceaccount": 47 return "客服帐号"; 48 case "messageconsume": 49 return "短信消耗"; 50 case "receivingrate": 51 return "接听率"; 52 case "youxiaop": 53 return "有效接听率"; 54 case "telamount": 55 return "电话量"; 56 case "extennum": 57 return "拨打分机个数"; 58 case "telconnum": 59 return "继续拨打分机次数"; 60 case "listenarea": 61 return "接听区域"; 62 case "specialfield": 63 return "专业领域"; 64 case "calltime": 65 return "接听时间"; 66 case "userstart": 67 return "当前状态"; 68 case "currentbalance": 69 return "当前余额"; 70 case "call400all": 71 return "400电话总量"; 72 case "call400youxiao": 73 return "400有效电话量"; 74 case "call400consume": 75 return "400消耗额"; 76 case "call400avgopp": 77 return "400平均商机费"; 78 case "call800all": 79 return "800电话总量"; 80 case "call800youxiao": 81 return "800有效电话量"; 82 case "call800consume": 83 return "800消耗额"; 84 case "call800avgopp": 85 return "800平均商机费"; 86 case "callall": 87 return "电话总量"; 88 case "callyouxiao": 89 return "总有效电话量"; 90 case "callconsume": 91 return "总消耗额"; 92 case "callavgoppo": 93 return "总平均商机费"; 94 case "hr": 95 return "小时"; 96 case "shangji400": 97 return "400商机费"; 98 case "shangji800": 99 return "800商机费"; 100 case "tongxun400": 101 return "400通讯费"; 102 case "tongxun800": 103 return "800通讯费"; 104 case "zongji400": 105 return "400总机费"; 106 case "zongji800": 107 return "800总机费"; 108 case "datet": 109 return "日期"; 110 case "opentime": 111 return "开通时间"; 112 case "allrecharge": 113 return "充值金额"; 114 case "Userstart": 115 return "状态"; 116 case "allnum": 117 return "总接听量"; 118 case "cbalance": 119 return "合作金额"; 120 case "allmoney": 121 return "续费额"; 122 case "username": 123 return "商户账号"; 124 case "isguoqi": 125 return "是否过期"; 126 case "accounttype": 127 return "商户类型"; 128 case "mphone": 129 return "客户手机号"; 130 case "specialText": 131 return "专长"; 132 case "uuname": 133 return "客服"; 134 case "opentimes": 135 return "合作时间"; 136 case "shangjifei": 137 return "商机费"; 138 139 } 140 return ""; 141 } 142 #endregion
构造URL POST请求
1 #region 构造URL POST请求 2 public static int timeout = 5000;//时间点 3 /// <summary> 4 /// 获取请求的反馈信息 5 /// </summary> 6 /// <param name="url"></param> 7 /// <param name="bData">参数字节数组</param> 8 /// <returns></returns> 9 private static String doPostRequest(string url, byte[] bData) 10 { 11 HttpWebRequest hwRequest; 12 HttpWebResponse hwResponse; 13 14 string strResult = string.Empty; 15 try 16 { 17 ServicePointManager.Expect100Continue = false;//远程服务器返回错误: (417) Expectation failed 异常源自HTTP1.1协议的一个规范: 100(Continue) 18 hwRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); 19 hwRequest.Timeout = timeout; 20 hwRequest.Method = "POST"; 21 hwRequest.ContentType = "application/x-www-form-urlencoded;charset=utf-8"; 22 hwRequest.ContentLength = bData.Length; 23 Stream smWrite = hwRequest.GetRequestStream(); 24 smWrite.Write(bData, 0, bData.Length); 25 smWrite.Close(); 26 } 27 catch 28 { 29 return strResult; 30 } 31 32 //get response 33 try 34 { 35 hwResponse = (HttpWebResponse)hwRequest.GetResponse(); 36 StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.UTF8); 37 strResult = srReader.ReadToEnd(); 38 srReader.Close(); 39 hwResponse.Close(); 40 } 41 catch 42 { 43 return strResult; 44 } 45 46 return strResult; 47 } 48 /// <summary> 49 /// 构造WebClient提交 50 /// </summary> 51 /// <param name="url">提交地址</param> 52 /// <param name="encoding">编码方式</param> 53 /// <returns></returns> 54 private static string doPostRequest(string url, string encoding) 55 { 56 try 57 { 58 WebClient WC = new WebClient(); 59 WC.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); 60 int p = url.IndexOf("?"); 61 string sData = url.Substring(p + 1); 62 url = url.Substring(0, p); 63 byte[] Data = Encoding.GetEncoding(encoding).GetBytes(sData); 64 byte[] Res = WC.UploadData(url, "POST", Data); 65 string result = Encoding.GetEncoding(encoding).GetString(Res); 66 return result; 67 } 68 catch 69 { 70 return ""; 71 } 72 } 73 #endregion
构造URL GET请求
1 #region 构造URL GET请求 2 /// <summary> 3 /// 获取请求的反馈信息 4 /// </summary> 5 /// <param name="url">地址</param> 6 /// <returns></returns> 7 public static string doGetRequest(string url) 8 { 9 HttpWebRequest hwRequest; 10 HttpWebResponse hwResponse; 11 12 string strResult = string.Empty; 13 try 14 { 15 hwRequest = (System.Net.HttpWebRequest)WebRequest.Create(url); 16 hwRequest.Timeout = timeout; 17 hwRequest.Method = "GET"; 18 hwRequest.ContentType = "application/x-www-form-urlencoded;charset=utf-8"; 19 } 20 catch 21 { 22 return strResult; 23 } 24 25 //get response 26 try 27 { 28 hwResponse = (HttpWebResponse)hwRequest.GetResponse(); 29 StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.UTF8); 30 strResult = srReader.ReadToEnd(); 31 srReader.Close(); 32 hwResponse.Close(); 33 } 34 catch 35 { 36 return strResult; 37 } 38 39 return strResult; 40 } 41 #endregion
POST请求
1 #region POST请求 2 public static string PostMethod(string url, string param) 3 { 4 byte[] data = Encoding.UTF8.GetBytes(param); 5 return doPostRequest(url, data); 6 } 7 /// <summary> 8 /// POST请求 9 /// </summary> 10 /// <param name="url">URL</param> 11 /// <param name="encoding">编码gb2312/utf8</param> 12 /// <param name="param">参数</param> 13 /// <returns>结果</returns> 14 public static string PostMethod(string url, string encoding, string param) 15 { 16 HttpWebRequest hwRequest; 17 HttpWebResponse hwResponse; 18 19 string strResult = string.Empty; 20 byte[] bData = null; 21 if (string.IsNullOrEmpty(param)) 22 { 23 int p = url.IndexOf("?"); 24 string sData = ""; 25 if (p > 0) 26 { 27 sData = url.Substring(p + 1); 28 url = url.Substring(0, p); 29 } 30 bData = Encoding.GetEncoding(encoding).GetBytes(sData); 31 32 } 33 else 34 { 35 bData = Encoding.GetEncoding(encoding).GetBytes(param); 36 } 37 try 38 { 39 ServicePointManager.Expect100Continue = false;//远程服务器返回错误: (417) Expectation failed 异常源自HTTP1.1协议的一个规范: 100(Continue) 40 hwRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); 41 hwRequest.Timeout = timeout; 42 hwRequest.Method = "POST"; 43 hwRequest.ContentType = "application/x-www-form-urlencoded"; 44 hwRequest.ContentLength = bData.Length; 45 Stream smWrite = hwRequest.GetRequestStream(); 46 smWrite.Write(bData, 0, bData.Length); 47 smWrite.Close(); 48 } 49 catch 50 { 51 return strResult; 52 } 53 //get response 54 try 55 { 56 hwResponse = (HttpWebResponse)hwRequest.GetResponse(); 57 StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.GetEncoding(encoding)); 58 strResult = srReader.ReadToEnd(); 59 srReader.Close(); 60 hwResponse.Close(); 61 } 62 catch 63 { 64 return strResult; 65 } 66 67 return strResult; 68 } 69 #endregion
访问提交创建文件 (供生成静态页面使用,无需模板)
1 #region 访问提交创建文件 (供生成静态页面使用,无需模板) 2 /// <summary> 3 /// 访问提交创建文件 (供生成静态页面使用,无需模板) 4 /// 调用实例 Utils.CreateFileHtml("http://www.xiaomi.com", Server.MapPath("/xxx.html")); 5 /// </summary> 6 /// <param name="url">原网址</param> 7 /// <param name="createpath">生成路径</param> 8 /// <returns>true false</returns> 9 public static bool CreateFileHtml(string url, string createpath) 10 { 11 if (!string.IsNullOrEmpty(url)) 12 { 13 string result = PostMethod(url, ""); 14 if (!string.IsNullOrEmpty(result)) 15 { 16 if (string.IsNullOrEmpty(createpath)) 17 { 18 createpath = "/default.html"; 19 } 20 string filepath = createpath.Substring(createpath.LastIndexOf(@"\")); 21 createpath = createpath.Substring(0, createpath.LastIndexOf(@"\")); 22 if (!Directory.Exists(createpath)) 23 { 24 Directory.CreateDirectory(createpath); 25 } 26 createpath = createpath + filepath; 27 try 28 { 29 FileStream fs2 = new FileStream(createpath, FileMode.Create); 30 StreamWriter sw = new StreamWriter(fs2, System.Text.Encoding.UTF8); 31 sw.Write(result); 32 sw.Close(); 33 fs2.Close(); 34 fs2.Dispose(); 35 return true; 36 } 37 catch { return false; } 38 } 39 return false; 40 } 41 return false; 42 } 43 /// <summary> 44 /// 访问提交创建文件 (供生成静态页面使用,需要模板) 45 /// 调用实例 Utils.CreateFileHtmlByTemp(html, Server.MapPath("/xxx.html")); 46 /// </summary> 47 /// <param name="url">原网址</param> 48 /// <param name="createpath">生成路径</param> 49 /// <returns>true false</returns> 50 public static bool CreateFileHtmlByTemp(string result, string createpath) 51 { 52 if (!string.IsNullOrEmpty(result)) 53 { 54 if (string.IsNullOrEmpty(createpath)) 55 { 56 createpath = "/default.html"; 57 } 58 string filepath = createpath.Substring(createpath.LastIndexOf(@"\")); 59 createpath = createpath.Substring(0, createpath.LastIndexOf(@"\")); 60 if (!Directory.Exists(createpath)) 61 { 62 Directory.CreateDirectory(createpath); 63 } 64 createpath = createpath + filepath; 65 try 66 { 67 FileStream fs2 = new FileStream(createpath, FileMode.Create); 68 StreamWriter sw = new StreamWriter(fs2, new UTF8Encoding(false));//去除UTF-8 BOM 69 sw.Write(result); 70 sw.Close(); 71 fs2.Close(); 72 fs2.Dispose(); 73 return true; 74 } 75 catch { return false; } 76 } 77 return false; 78 } 79 #endregion
汉字转拼音
1 #region 汉字转拼音 2 3 #region 数组信息 4 private static int[] pyValue = new int[] 5 6 { 7 -20319, -20317, -20304, -20295, -20292, -20283, -20265, -20257, -20242, 8 9 -20230, -20051, -20036, -20032, -20026, -20002, -19990, -19986, -19982, 10 11 -19976, -19805, -19784, -19775, -19774, -19763, -19756, -19751, -19746, 12 13 -19741, -19739, -19728, -19725, -19715, -19540, -19531, -19525, -19515, 14 15 -19500, -19484, -19479, -19467, -19289, -19288, -19281, -19275, -19270, 16 17 -19263, -19261, -19249, -19243, -19242, -19238, -19235, -19227, -19224, 18 19 -19218, -19212, -19038, -19023, -19018, -19006, -19003, -18996, -18977, 20 21 -18961, -18952, -18783, -18774, -18773, -18763, -18756, -18741, -18735, 22 23 -18731, -18722, -18710, -18697, -18696, -18526, -18518, -18501, -18490, 24 25 -18478, -18463, -18448, -18447, -18446, -18239, -18237, -18231, -18220, 26 27 -18211, -18201, -18184, -18183, -18181, -18012, -17997, -17988, -17970, 28 29 -17964, -17961, -17950, -17947, -17931, -17928, -17922, -17759, -17752, 30 31 -17733, -17730, -17721, -17703, -17701, -17697, -17692, -17683, -17676, 32 33 -17496, -17487, -17482, -17468, -17454, -17433, -17427, -17417, -17202, 34 35 -17185, -16983, -16970, -16942, -16915, -16733, -16708, -16706, -16689, 36 37 -16664, -16657, -16647, -16474, -16470, -16465, -16459, -16452, -16448, 38 39 -16433, -16429, -16427, -16423, -16419, -16412, -16407, -16403, -16401, 40 41 -16393, -16220, -16216, -16212, -16205, -16202, -16187, -16180, -16171, 42 43 -16169, -16158, -16155, -15959, -15958, -15944, -15933, -15920, -15915, 44 45 -15903, -15889, -15878, -15707, -15701, -15681, -15667, -15661, -15659, 46 47 -15652, -15640, -15631, -15625, -15454, -15448, -15436, -15435, -15419, 48 49 -15416, -15408, -15394, -15385, -15377, -15375, -15369, -15363, -15362, 50 51 -15183, -15180, -15165, -15158, -15153, -15150, -15149, -15144, -15143, 52 53 -15141, -15140, -15139, -15128, -15121, -15119, -15117, -15110, -15109, 54 55 -14941, -14937, -14933, -14930, -14929, -14928, -14926, -14922, -14921, 56 57 -14914, -14908, -14902, -14894, -14889, -14882, -14873, -14871, -14857, 58 59 -14678, -14674, -14670, -14668, -14663, -14654, -14645, -14630, -14594, 60 61 -14429, -14407, -14399, -14384, -14379, -14368, -14355, -14353, -14345, 62 63 -14170, -14159, -14151, -14149, -14145, -14140, -14137, -14135, -14125, 64 65 -14123, -14122, -14112, -14109, -14099, -14097, -14094, -14092, -14090, 66 67 -14087, -14083, -13917, -13914, -13910, -13907, -13906, -13905, -13896, 68 69 -13894, -13878, -13870, -13859, -13847, -13831, -13658, -13611, -13601, 70 71 -13406, -13404, -13400, -13398, -13395, -13391, -13387, -13383, -13367, 72 73 -13359, -13356, -13343, -13340, -13329, -13326, -13318, -13147, -13138, 74 75 -13120, -13107, -13096, -13095, -13091, -13076, -13068, -13063, -13060, 76 77 -12888, -12875, -12871, -12860, -12858, -12852, -12849, -12838, -12831, 78 79 -12829, -12812, -12802, -12607, -12597, -12594, -12585, -12556, -12359, 80 81 -12346, -12320, -12300, -12120, -12099, -12089, -12074, -12067, -12058, 82 83 -12039, -11867, -11861, -11847, -11831, -11798, -11781, -11604, -11589, 84 85 -11536, -11358, -11340, -11339, -11324, -11303, -11097, -11077, -11067, 86 87 -11055, -11052, -11045, -11041, -11038, -11024, -11020, -11019, -11018, 88 89 -11014, -10838, -10832, -10815, -10800, -10790, -10780, -10764, -10587, 90 91 -10544, -10533, -10519, -10331, -10329, -10328, -10322, -10315, -10309, 92 93 -10307, -10296, -10281, -10274, -10270, -10262, -10260, -10256, -10254 94 95 }; 96 97 private static string[] pyName = new string[] 98 99 { 100 "A", "Ai", "An", "Ang", "Ao", "Ba", "Bai", "Ban", "Bang", "Bao", "Bei", 101 102 "Ben", "Beng", "Bi", "Bian", "Biao", "Bie", "Bin", "Bing", "Bo", "Bu", 103 104 "Ba", "Cai", "Can", "Cang", "Cao", "Ce", "Ceng", "Cha", "Chai", "Chan", 105 106 "Chang", "Chao", "Che", "Chen", "Cheng", "Chi", "Chong", "Chou", "Chu", 107 108 "Chuai", "Chuan", "Chuang", "Chui", "Chun", "Chuo", "Ci", "Cong", "Cou", 109 110 "Cu", "Cuan", "Cui", "Cun", "Cuo", "Da", "Dai", "Dan", "Dang", "Dao", "De", 111 112 "Deng", "Di", "Dian", "Diao", "Die", "Ding", "Diu", "Dong", "Dou", "Du", 113 114 "Duan", "Dui", "Dun", "Duo", "E", "En", "Er", "Fa", "Fan", "Fang", "Fei", 115 116 "Fen", "Feng", "Fo", "Fou", "Fu", "Ga", "Gai", "Gan", "Gang", "Gao", "Ge", 117 118 "Gei", "Gen", "Geng", "Gong", "Gou", "Gu", "Gua", "Guai", "Guan", "Guang", 119 120 "Gui", "Gun", "Guo", "Ha", "Hai", "Han", "Hang", "Hao", "He", "Hei", "Hen", 121 122 "Heng", "Hong", "Hou", "Hu", "Hua", "Huai", "Huan", "Huang", "Hui", "Hun", 123 124 "Huo", "Ji", "Jia", "Jian", "Jiang", "Jiao", "Jie", "Jin", "Jing", "Jiong", 125 126 "Jiu", "Ju", "Juan", "Jue", "Jun", "Ka", "Kai", "Kan", "Kang", "Kao", "Ke", 127 128 "Ken", "Keng", "Kong", "Kou", "Ku", "Kua", "Kuai", "Kuan", "Kuang", "Kui", 129 130 "Kun", "Kuo", "La", "Lai", "Lan", "Lang", "Lao", "Le", "Lei", "Leng", "Li", 131 132 "Lia", "Lian", "Liang", "Liao", "Lie", "Lin", "Ling", "Liu", "Long", "Lou", 133 134 "Lu", "Lv", "Luan", "Lue", "Lun", "Luo", "Ma", "Mai", "Man", "Mang", "Mao", 135 136 "Me", "Mei", "Men", "Meng", "Mi", "Mian", "Miao", "Mie", "Min", "Ming", "Miu", 137 138 "Mo", "Mou", "Mu", "Na", "Nai", "Nan", "Nang", "Nao", "Ne", "Nei", "Nen", 139 140 "Neng", "Ni", "Nian", "Niang", "Niao", "Nie", "Nin", "Ning", "Niu", "Nong", 141 142 "Nu", "Nv", "Nuan", "Nue", "Nuo", "O", "Ou", "Pa", "Pai", "Pan", "Pang", 143 144 "Pao", "Pei", "Pen", "Peng", "Pi", "Pian", "Piao", "Pie", "Pin", "Ping", 145 146 "Po", "Pu", "Qi", "Qia", "Qian", "Qiang", "Qiao", "Qie", "Qin", "Qing", 147 148 "Qiong", "Qiu", "Qu", "Quan", "Que", "Qun", "Ran", "Rang", "Rao", "Re", 149 150 "Ren", "Reng", "Ri", "Rong", "Rou", "Ru", "Ruan", "Rui", "Run", "Ruo", 151 152 "Sa", "Sai", "San", "Sang", "Sao", "Se", "Sen", "Seng", "Sha", "Shai", 153 154 "Shan", "Shang", "Shao", "She", "Shen", "Sheng", "Shi", "Shou", "Shu", 155 156 "Shua", "Shuai", "Shuan", "Shuang", "Shui", "Shun", "Shuo", "Si", "Song", 157 158 "Sou", "Su", "Suan", "Sui", "Sun", "Suo", "Ta", "Tai", "Tan", "Tang", 159 160 "Tao", "Te", "Teng", "Ti", "Tian", "Tiao", "Tie", "Ting", "Tong", "Tou", 161 162 "Tu", "Tuan", "Tui", "Tun", "Tuo", "Wa", "Wai", "Wan", "Wang", "Wei", 163 164 "Wen", "Weng", "Wo", "Wu", "Xi", "Xia", "Xian", "Xiang", "Xiao", "Xie", 165 166 "Xin", "Xing", "Xiong", "Xiu", "Xu", "Xuan", "Xue", "Xun", "Ya", "Yan", 167 168 "Yang", "Yao", "Ye", "Yi", "Yin", "Ying", "Yo", "Yong", "You", "Yu", 169 170 "Yuan", "Yue", "Yun", "Za", "Zai", "Zan", "Zang", "Zao", "Ze", "Zei", 171 172 "Zen", "Zeng", "Zha", "Zhai", "Zhan", "Zhang", "Zhao", "Zhe", "Zhen", 173 174 "Zheng", "Zhi", "Zhong", "Zhou", "Zhu", "Zhua", "Zhuai", "Zhuan", 175 176 "Zhuang", "Zhui", "Zhun", "Zhuo", "Zi", "Zong", "Zou", "Zu", "Zuan", 177 178 "Zui", "Zun", "Zuo" 179 }; 180 181 #region 二级汉字 182 /// <summary> 183 /// 二级汉字数组 184 /// </summary> 185 private static string[] otherChinese = new string[] 186 { 187 "亍","丌","兀","丐","廿","卅","丕","亘","丞","鬲","孬","噩","丨","禺","丿" 188 ,"匕","乇","夭","爻","卮","氐","囟","胤","馗","毓","睾","鼗","丶","亟","鼐","乜" 189 ,"乩","亓","芈","孛","啬","嘏","仄","厍","厝","厣","厥","厮","靥","赝","匚","叵" 190 ,"匦","匮","匾","赜","卦","卣","刂","刈","刎","刭","刳","刿","剀","剌","剞","剡" 191 ,"剜","蒯","剽","劂","劁","劐","劓","冂","罔","亻","仃","仉","仂","仨","仡","仫" 192 ,"仞","伛","仳","伢","佤","仵","伥","伧","伉","伫","佞","佧","攸","佚","佝" 193 ,"佟","佗","伲","伽","佶","佴","侑","侉","侃","侏","佾","佻","侪","佼","侬" 194 ,"侔","俦","俨","俪","俅","俚","俣","俜","俑","俟","俸","倩","偌","俳","倬","倏" 195 ,"倮","倭","俾","倜","倌","倥","倨","偾","偃","偕","偈","偎","偬","偻","傥","傧" 196 ,"傩","傺","僖","儆","僭","僬","僦","僮","儇","儋","仝","氽","佘","佥","俎","龠" 197 ,"汆","籴","兮","巽","黉","馘","冁","夔","勹","匍","訇","匐","凫","夙","兕","亠" 198 ,"兖","亳","衮","袤","亵","脔","裒","禀","嬴","蠃","羸","冫","冱","冽","冼" 199 ,"凇","冖","冢","冥","讠","讦","讧","讪","讴","讵","讷","诂","诃","诋","诏" 200 ,"诎","诒","诓","诔","诖","诘","诙","诜","诟","诠","诤","诨","诩","诮","诰","诳" 201 ,"诶","诹","诼","诿","谀","谂","谄","谇","谌","谏","谑","谒","谔","谕","谖","谙" 202 ,"谛","谘","谝","谟","谠","谡","谥","谧","谪","谫","谮","谯","谲","谳","谵","谶" 203 ,"卩","卺","阝","阢","阡","阱","阪","阽","阼","陂","陉","陔","陟","陧","陬","陲" 204 ,"陴","隈","隍","隗","隰","邗","邛","邝","邙","邬","邡","邴","邳","邶","邺" 205 ,"邸","邰","郏","郅","邾","郐","郄","郇","郓","郦","郢","郜","郗","郛","郫" 206 ,"郯","郾","鄄","鄢","鄞","鄣","鄱","鄯","鄹","酃","酆","刍","奂","劢","劬","劭" 207 ,"劾","哿","勐","勖","勰","叟","燮","矍","廴","凵","凼","鬯","厶","弁","畚","巯" 208 ,"坌","垩","垡","塾","墼","壅","壑","圩","圬","圪","圳","圹","圮","圯","坜","圻" 209 ,"坂","坩","垅","坫","垆","坼","坻","坨","坭","坶","坳","垭","垤","垌","垲","埏" 210 ,"垧","垴","垓","垠","埕","埘","埚","埙","埒","垸","埴","埯","埸","埤","埝" 211 ,"堋","堍","埽","埭","堀","堞","堙","塄","堠","塥","塬","墁","墉","墚","墀" 212 ,"馨","鼙","懿","艹","艽","艿","芏","芊","芨","芄","芎","芑","芗","芙","芫","芸" 213 ,"芾","芰","苈","苊","苣","芘","芷","芮","苋","苌","苁","芩","芴","芡","芪","芟" 214 ,"苄","苎","芤","苡","茉","苷","苤","茏","茇","苜","苴","苒","苘","茌","苻","苓" 215 ,"茑","茚","茆","茔","茕","苠","苕","茜","荑","荛","荜","茈","莒","茼","茴","茱" 216 ,"莛","荞","茯","荏","荇","荃","荟","荀","茗","荠","茭","茺","茳","荦","荥" 217 ,"荨","茛","荩","荬","荪","荭","荮","莰","荸","莳","莴","莠","莪","莓","莜" 218 ,"莅","荼","莶","莩","荽","莸","荻","莘","莞","莨","莺","莼","菁","萁","菥","菘" 219 ,"堇","萘","萋","菝","菽","菖","萜","萸","萑","萆","菔","菟","萏","萃","菸","菹" 220 ,"菪","菅","菀","萦","菰","菡","葜","葑","葚","葙","葳","蒇","蒈","葺","蒉","葸" 221 ,"萼","葆","葩","葶","蒌","蒎","萱","葭","蓁","蓍","蓐","蓦","蒽","蓓","蓊","蒿" 222 ,"蒺","蓠","蒡","蒹","蒴","蒗","蓥","蓣","蔌","甍","蔸","蓰","蔹","蔟","蔺" 223 ,"蕖","蔻","蓿","蓼","蕙","蕈","蕨","蕤","蕞","蕺","瞢","蕃","蕲","蕻","薤" 224 ,"薨","薇","薏","蕹","薮","薜","薅","薹","薷","薰","藓","藁","藜","藿","蘧","蘅" 225 ,"蘩","蘖","蘼","廾","弈","夼","奁","耷","奕","奚","奘","匏","尢","尥","尬","尴" 226 ,"扌","扪","抟","抻","拊","拚","拗","拮","挢","拶","挹","捋","捃","掭","揶","捱" 227 ,"捺","掎","掴","捭","掬","掊","捩","掮","掼","揲","揸","揠","揿","揄","揞","揎" 228 ,"摒","揆","掾","摅","摁","搋","搛","搠","搌","搦","搡","摞","撄","摭","撖" 229 ,"摺","撷","撸","撙","撺","擀","擐","擗","擤","擢","攉","攥","攮","弋","忒" 230 ,"甙","弑","卟","叱","叽","叩","叨","叻","吒","吖","吆","呋","呒","呓","呔","呖" 231 ,"呃","吡","呗","呙","吣","吲","咂","咔","呷","呱","呤","咚","咛","咄","呶","呦" 232 ,"咝","哐","咭","哂","咴","哒","咧","咦","哓","哔","呲","咣","哕","咻","咿","哌" 233 ,"哙","哚","哜","咩","咪","咤","哝","哏","哞","唛","哧","唠","哽","唔","哳","唢" 234 ,"唣","唏","唑","唧","唪","啧","喏","喵","啉","啭","啁","啕","唿","啐","唼" 235 ,"唷","啖","啵","啶","啷","唳","唰","啜","喋","嗒","喃","喱","喹","喈","喁" 236 ,"喟","啾","嗖","喑","啻","嗟","喽","喾","喔","喙","嗪","嗷","嗉","嘟","嗑","嗫" 237 ,"嗬","嗔","嗦","嗝","嗄","嗯","嗥","嗲","嗳","嗌","嗍","嗨","嗵","嗤","辔","嘞" 238 ,"嘈","嘌","嘁","嘤","嘣","嗾","嘀","嘧","嘭","噘","嘹","噗","嘬","噍","噢","噙" 239 ,"噜","噌","噔","嚆","噤","噱","噫","噻","噼","嚅","嚓","嚯","囔","囗","囝","囡" 240 ,"囵","囫","囹","囿","圄","圊","圉","圜","帏","帙","帔","帑","帱","帻","帼" 241 ,"帷","幄","幔","幛","幞","幡","岌","屺","岍","岐","岖","岈","岘","岙","岑" 242 ,"岚","岜","岵","岢","岽","岬","岫","岱","岣","峁","岷","峄","峒","峤","峋","峥" 243 ,"崂","崃","崧","崦","崮","崤","崞","崆","崛","嵘","崾","崴","崽","嵬","嵛","嵯" 244 ,"嵝","嵫","嵋","嵊","嵩","嵴","嶂","嶙","嶝","豳","嶷","巅","彳","彷","徂","徇" 245 ,"徉","後","徕","徙","徜","徨","徭","徵","徼","衢","彡","犭","犰","犴","犷","犸" 246 ,"狃","狁","狎","狍","狒","狨","狯","狩","狲","狴","狷","猁","狳","猃","狺" 247 ,"狻","猗","猓","猡","猊","猞","猝","猕","猢","猹","猥","猬","猸","猱","獐" 248 ,"獍","獗","獠","獬","獯","獾","舛","夥","飧","夤","夂","饣","饧","饨","饩","饪" 249 ,"饫","饬","饴","饷","饽","馀","馄","馇","馊","馍","馐","馑","馓","馔","馕","庀" 250 ,"庑","庋","庖","庥","庠","庹","庵","庾","庳","赓","廒","廑","廛","廨","廪","膺" 251 ,"忄","忉","忖","忏","怃","忮","怄","忡","忤","忾","怅","怆","忪","忭","忸","怙" 252 ,"怵","怦","怛","怏","怍","怩","怫","怊","怿","怡","恸","恹","恻","恺","恂" 253 ,"恪","恽","悖","悚","悭","悝","悃","悒","悌","悛","惬","悻","悱","惝","惘" 254 ,"惆","惚","悴","愠","愦","愕","愣","惴","愀","愎","愫","慊","慵","憬","憔","憧" 255 ,"憷","懔","懵","忝","隳","闩","闫","闱","闳","闵","闶","闼","闾","阃","阄","阆" 256 ,"阈","阊","阋","阌","阍","阏","阒","阕","阖","阗","阙","阚","丬","爿","戕","氵" 257 ,"汔","汜","汊","沣","沅","沐","沔","沌","汨","汩","汴","汶","沆","沩","泐","泔" 258 ,"沭","泷","泸","泱","泗","沲","泠","泖","泺","泫","泮","沱","泓","泯","泾" 259 ,"洹","洧","洌","浃","浈","洇","洄","洙","洎","洫","浍","洮","洵","洚","浏" 260 ,"浒","浔","洳","涑","浯","涞","涠","浞","涓","涔","浜","浠","浼","浣","渚","淇" 261 ,"淅","淞","渎","涿","淠","渑","淦","淝","淙","渖","涫","渌","涮","渫","湮","湎" 262 ,"湫","溲","湟","溆","湓","湔","渲","渥","湄","滟","溱","溘","滠","漭","滢","溥" 263 ,"溧","溽","溻","溷","滗","溴","滏","溏","滂","溟","潢","潆","潇","漤","漕","滹" 264 ,"漯","漶","潋","潴","漪","漉","漩","澉","澍","澌","潸","潲","潼","潺","濑" 265 ,"濉","澧","澹","澶","濂","濡","濮","濞","濠","濯","瀚","瀣","瀛","瀹","瀵" 266 ,"灏","灞","宀","宄","宕","宓","宥","宸","甯","骞","搴","寤","寮","褰","寰","蹇" 267 ,"謇","辶","迓","迕","迥","迮","迤","迩","迦","迳","迨","逅","逄","逋","逦","逑" 268 ,"逍","逖","逡","逵","逶","逭","逯","遄","遑","遒","遐","遨","遘","遢","遛","暹" 269 ,"遴","遽","邂","邈","邃","邋","彐","彗","彖","彘","尻","咫","屐","屙","孱","屣" 270 ,"屦","羼","弪","弩","弭","艴","弼","鬻","屮","妁","妃","妍","妩","妪","妣" 271 ,"妗","姊","妫","妞","妤","姒","妲","妯","姗","妾","娅","娆","姝","娈","姣" 272 ,"姘","姹","娌","娉","娲","娴","娑","娣","娓","婀","婧","婊","婕","娼","婢","婵" 273 ,"胬","媪","媛","婷","婺","媾","嫫","媲","嫒","嫔","媸","嫠","嫣","嫱","嫖","嫦" 274 ,"嫘","嫜","嬉","嬗","嬖","嬲","嬷","孀","尕","尜","孚","孥","孳","孑","孓","孢" 275 ,"驵","驷","驸","驺","驿","驽","骀","骁","骅","骈","骊","骐","骒","骓","骖","骘" 276 ,"骛","骜","骝","骟","骠","骢","骣","骥","骧","纟","纡","纣","纥","纨","纩" 277 ,"纭","纰","纾","绀","绁","绂","绉","绋","绌","绐","绔","绗","绛","绠","绡" 278 ,"绨","绫","绮","绯","绱","绲","缍","绶","绺","绻","绾","缁","缂","缃","缇","缈" 279 ,"缋","缌","缏","缑","缒","缗","缙","缜","缛","缟","缡","缢","缣","缤","缥","缦" 280 ,"缧","缪","缫","缬","缭","缯","缰","缱","缲","缳","缵","幺","畿","巛","甾","邕" 281 ,"玎","玑","玮","玢","玟","珏","珂","珑","玷","玳","珀","珉","珈","珥","珙","顼" 282 ,"琊","珩","珧","珞","玺","珲","琏","琪","瑛","琦","琥","琨","琰","琮","琬" 283 ,"琛","琚","瑁","瑜","瑗","瑕","瑙","瑷","瑭","瑾","璜","璎","璀","璁","璇" 284 ,"璋","璞","璨","璩","璐","璧","瓒","璺","韪","韫","韬","杌","杓","杞","杈","杩" 285 ,"枥","枇","杪","杳","枘","枧","杵","枨","枞","枭","枋","杷","杼","柰","栉","柘" 286 ,"栊","柩","枰","栌","柙","枵","柚","枳","柝","栀","柃","枸","柢","栎","柁","柽" 287 ,"栲","栳","桠","桡","桎","桢","桄","桤","梃","栝","桕","桦","桁","桧","桀","栾" 288 ,"桊","桉","栩","梵","梏","桴","桷","梓","桫","棂","楮","棼","椟","椠","棹" 289 ,"椤","棰","椋","椁","楗","棣","椐","楱","椹","楠","楂","楝","榄","楫","榀" 290 ,"榘","楸","椴","槌","榇","榈","槎","榉","楦","楣","楹","榛","榧","榻","榫","榭" 291 ,"槔","榱","槁","槊","槟","榕","槠","榍","槿","樯","槭","樗","樘","橥","槲","橄" 292 ,"樾","檠","橐","橛","樵","檎","橹","樽","樨","橘","橼","檑","檐","檩","檗","檫" 293 ,"猷","獒","殁","殂","殇","殄","殒","殓","殍","殚","殛","殡","殪","轫","轭","轱" 294 ,"轲","轳","轵","轶","轸","轷","轹","轺","轼","轾","辁","辂","辄","辇","辋" 295 ,"辍","辎","辏","辘","辚","軎","戋","戗","戛","戟","戢","戡","戥","戤","戬" 296 ,"臧","瓯","瓴","瓿","甏","甑","甓","攴","旮","旯","旰","昊","昙","杲","昃","昕" 297 ,"昀","炅","曷","昝","昴","昱","昶","昵","耆","晟","晔","晁","晏","晖","晡","晗" 298 ,"晷","暄","暌","暧","暝","暾","曛","曜","曦","曩","贲","贳","贶","贻","贽","赀" 299 ,"赅","赆","赈","赉","赇","赍","赕","赙","觇","觊","觋","觌","觎","觏","觐","觑" 300 ,"牮","犟","牝","牦","牯","牾","牿","犄","犋","犍","犏","犒","挈","挲","掰" 301 ,"搿","擘","耄","毪","毳","毽","毵","毹","氅","氇","氆","氍","氕","氘","氙" 302 ,"氚","氡","氩","氤","氪","氲","攵","敕","敫","牍","牒","牖","爰","虢","刖","肟" 303 ,"肜","肓","肼","朊","肽","肱","肫","肭","肴","肷","胧","胨","胩","胪","胛","胂" 304 ,"胄","胙","胍","胗","朐","胝","胫","胱","胴","胭","脍","脎","胲","胼","朕","脒" 305 ,"豚","脶","脞","脬","脘","脲","腈","腌","腓","腴","腙","腚","腱","腠","腩","腼" 306 ,"腽","腭","腧","塍","媵","膈","膂","膑","滕","膣","膪","臌","朦","臊","膻" 307 ,"臁","膦","欤","欷","欹","歃","歆","歙","飑","飒","飓","飕","飙","飚","殳" 308 ,"彀","毂","觳","斐","齑","斓","於","旆","旄","旃","旌","旎","旒","旖","炀","炜" 309 ,"炖","炝","炻","烀","炷","炫","炱","烨","烊","焐","焓","焖","焯","焱","煳","煜" 310 ,"煨","煅","煲","煊","煸","煺","熘","熳","熵","熨","熠","燠","燔","燧","燹","爝" 311 ,"爨","灬","焘","煦","熹","戾","戽","扃","扈","扉","礻","祀","祆","祉","祛","祜" 312 ,"祓","祚","祢","祗","祠","祯","祧","祺","禅","禊","禚","禧","禳","忑","忐" 313 ,"怼","恝","恚","恧","恁","恙","恣","悫","愆","愍","慝","憩","憝","懋","懑" 314 ,"戆","肀","聿","沓","泶","淼","矶","矸","砀","砉","砗","砘","砑","斫","砭","砜" 315 ,"砝","砹","砺","砻","砟","砼","砥","砬","砣","砩","硎","硭","硖","硗","砦","硐" 316 ,"硇","硌","硪","碛","碓","碚","碇","碜","碡","碣","碲","碹","碥","磔","磙","磉" 317 ,"磬","磲","礅","磴","礓","礤","礞","礴","龛","黹","黻","黼","盱","眄","眍","盹" 318 ,"眇","眈","眚","眢","眙","眭","眦","眵","眸","睐","睑","睇","睃","睚","睨" 319 ,"睢","睥","睿","瞍","睽","瞀","瞌","瞑","瞟","瞠","瞰","瞵","瞽","町","畀" 320 ,"畎","畋","畈","畛","畲","畹","疃","罘","罡","罟","詈","罨","罴","罱","罹","羁" 321 ,"罾","盍","盥","蠲","钅","钆","钇","钋","钊","钌","钍","钏","钐","钔","钗","钕" 322 ,"钚","钛","钜","钣","钤","钫","钪","钭","钬","钯","钰","钲","钴","钶","钷","钸" 323 ,"钹","钺","钼","钽","钿","铄","铈","铉","铊","铋","铌","铍","铎","铐","铑","铒" 324 ,"铕","铖","铗","铙","铘","铛","铞","铟","铠","铢","铤","铥","铧","铨","铪" 325 ,"铩","铫","铮","铯","铳","铴","铵","铷","铹","铼","铽","铿","锃","锂","锆" 326 ,"锇","锉","锊","锍","锎","锏","锒","锓","锔","锕","锖","锘","锛","锝","锞","锟" 327 ,"锢","锪","锫","锩","锬","锱","锲","锴","锶","锷","锸","锼","锾","锿","镂","锵" 328 ,"镄","镅","镆","镉","镌","镎","镏","镒","镓","镔","镖","镗","镘","镙","镛","镞" 329 ,"镟","镝","镡","镢","镤","镥","镦","镧","镨","镩","镪","镫","镬","镯","镱","镲" 330 ,"镳","锺","矧","矬","雉","秕","秭","秣","秫","稆","嵇","稃","稂","稞","稔" 331 ,"稹","稷","穑","黏","馥","穰","皈","皎","皓","皙","皤","瓞","瓠","甬","鸠" 332 ,"鸢","鸨","鸩","鸪","鸫","鸬","鸲","鸱","鸶","鸸","鸷","鸹","鸺","鸾","鹁","鹂" 333 ,"鹄","鹆","鹇","鹈","鹉","鹋","鹌","鹎","鹑","鹕","鹗","鹚","鹛","鹜","鹞","鹣" 334 ,"鹦","鹧","鹨","鹩","鹪","鹫","鹬","鹱","鹭","鹳","疒","疔","疖","疠","疝","疬" 335 ,"疣","疳","疴","疸","痄","疱","疰","痃","痂","痖","痍","痣","痨","痦","痤","痫" 336 ,"痧","瘃","痱","痼","痿","瘐","瘀","瘅","瘌","瘗","瘊","瘥","瘘","瘕","瘙" 337 ,"瘛","瘼","瘢","瘠","癀","瘭","瘰","瘿","瘵","癃","瘾","瘳","癍","癞","癔" 338 ,"癜","癖","癫","癯","翊","竦","穸","穹","窀","窆","窈","窕","窦","窠","窬","窨" 339 ,"窭","窳","衤","衩","衲","衽","衿","袂","袢","裆","袷","袼","裉","裢","裎","裣" 340 ,"裥","裱","褚","裼","裨","裾","裰","褡","褙","褓","褛","褊","褴","褫","褶","襁" 341 ,"襦","襻","疋","胥","皲","皴","矜","耒","耔","耖","耜","耠","耢","耥","耦","耧" 342 ,"耩","耨","耱","耋","耵","聃","聆","聍","聒","聩","聱","覃","顸","颀","颃" 343 ,"颉","颌","颍","颏","颔","颚","颛","颞","颟","颡","颢","颥","颦","虍","虔" 344 ,"虬","虮","虿","虺","虼","虻","蚨","蚍","蚋","蚬","蚝","蚧","蚣","蚪","蚓","蚩" 345 ,"蚶","蛄","蚵","蛎","蚰","蚺","蚱","蚯","蛉","蛏","蚴","蛩","蛱","蛲","蛭","蛳" 346 ,"蛐","蜓","蛞","蛴","蛟","蛘","蛑","蜃","蜇","蛸","蜈","蜊","蜍","蜉","蜣","蜻" 347 ,"蜞","蜥","蜮","蜚","蜾","蝈","蜴","蜱","蜩","蜷","蜿","螂","蜢","蝽","蝾","蝻" 348 ,"蝠","蝰","蝌","蝮","螋","蝓","蝣","蝼","蝤","蝙","蝥","螓","螯","螨","蟒" 349 ,"蟆","螈","螅","螭","螗","螃","螫","蟥","螬","螵","螳","蟋","蟓","螽","蟑" 350 ,"蟀","蟊","蟛","蟪","蟠","蟮","蠖","蠓","蟾","蠊","蠛","蠡","蠹","蠼","缶","罂" 351 ,"罄","罅","舐","竺","竽","笈","笃","笄","笕","笊","笫","笏","筇","笸","笪","笙" 352 ,"笮","笱","笠","笥","笤","笳","笾","笞","筘","筚","筅","筵","筌","筝","筠","筮" 353 ,"筻","筢","筲","筱","箐","箦","箧","箸","箬","箝","箨","箅","箪","箜","箢","箫" 354 ,"箴","篑","篁","篌","篝","篚","篥","篦","篪","簌","篾","篼","簏","簖","簋" 355 ,"簟","簪","簦","簸","籁","籀","臾","舁","舂","舄","臬","衄","舡","舢","舣" 356 ,"舭","舯","舨","舫","舸","舻","舳","舴","舾","艄","艉","艋","艏","艚","艟","艨" 357 ,"衾","袅","袈","裘","裟","襞","羝","羟","羧","羯","羰","羲","籼","敉","粑","粝" 358 ,"粜","粞","粢","粲","粼","粽","糁","糇","糌","糍","糈","糅","糗","糨","艮","暨" 359 ,"羿","翎","翕","翥","翡","翦","翩","翮","翳","糸","絷","綦","綮","繇","纛","麸" 360 ,"麴","赳","趄","趔","趑","趱","赧","赭","豇","豉","酊","酐","酎","酏","酤" 361 ,"酢","酡","酰","酩","酯","酽","酾","酲","酴","酹","醌","醅","醐","醍","醑" 362 ,"醢","醣","醪","醭","醮","醯","醵","醴","醺","豕","鹾","趸","跫","踅","蹙","蹩" 363 ,"趵","趿","趼","趺","跄","跖","跗","跚","跞","跎","跏","跛","跆","跬","跷","跸" 364 ,"跣","跹","跻","跤","踉","跽","踔","踝","踟","踬","踮","踣","踯","踺","蹀","踹" 365 ,"踵","踽","踱","蹉","蹁","蹂","蹑","蹒","蹊","蹰","蹶","蹼","蹯","蹴","躅","躏" 366 ,"躔","躐","躜","躞","豸","貂","貊","貅","貘","貔","斛","觖","觞","觚","觜" 367 ,"觥","觫","觯","訾","謦","靓","雩","雳","雯","霆","霁","霈","霏","霎","霪" 368 ,"霭","霰","霾","龀","龃","龅","龆","龇","龈","龉","龊","龌","黾","鼋","鼍","隹" 369 ,"隼","隽","雎","雒","瞿","雠","銎","銮","鋈","錾","鍪","鏊","鎏","鐾","鑫","鱿" 370 ,"鲂","鲅","鲆","鲇","鲈","稣","鲋","鲎","鲐","鲑","鲒","鲔","鲕","鲚","鲛","鲞" 371 ,"鲟","鲠","鲡","鲢","鲣","鲥","鲦","鲧","鲨","鲩","鲫","鲭","鲮","鲰","鲱","鲲" 372 ,"鲳","鲴","鲵","鲶","鲷","鲺","鲻","鲼","鲽","鳄","鳅","鳆","鳇","鳊","鳋" 373 ,"鳌","鳍","鳎","鳏","鳐","鳓","鳔","鳕","鳗","鳘","鳙","鳜","鳝","鳟","鳢" 374 ,"靼","鞅","鞑","鞒","鞔","鞯","鞫","鞣","鞲","鞴","骱","骰","骷","鹘","骶","骺" 375 ,"骼","髁","髀","髅","髂","髋","髌","髑","魅","魃","魇","魉","魈","魍","魑","飨" 376 ,"餍","餮","饕","饔","髟","髡","髦","髯","髫","髻","髭","髹","鬈","鬏","鬓","鬟" 377 ,"鬣","麽","麾","縻","麂","麇","麈","麋","麒","鏖","麝","麟","黛","黜","黝","黠" 378 ,"黟","黢","黩","黧","黥","黪","黯","鼢","鼬","鼯","鼹","鼷","鼽","鼾","齄" 379 }; 380 381 /// <summary> 382 /// 二级汉字对应拼音数组 383 /// </summary> 384 private static string[] otherPinYin = new string[] 385 { 386 "Chu","Ji","Wu","Gai","Nian","Sa","Pi","Gen","Cheng","Ge","Nao","E","Shu","Yu","Pie","Bi", 387 "Tuo","Yao","Yao","Zhi","Di","Xin","Yin","Kui","Yu","Gao","Tao","Dian","Ji","Nai","Nie","Ji", 388 "Qi","Mi","Bei","Se","Gu","Ze","She","Cuo","Yan","Jue","Si","Ye","Yan","Fang","Po","Gui", 389 "Kui","Bian","Ze","Gua","You","Ce","Yi","Wen","Jing","Ku","Gui","Kai","La","Ji","Yan","Wan", 390 "Kuai","Piao","Jue","Qiao","Huo","Yi","Tong","Wang","Dan","Ding","Zhang","Le","Sa","Yi","Mu","Ren", 391 "Yu","Pi","Ya","Wa","Wu","Chang","Cang","Kang","Zhu","Ning","Ka","You","Yi","Gou","Tong","Tuo", 392 "Ni","Ga","Ji","Er","You","Kua","Kan","Zhu","Yi","Tiao","Chai","Jiao","Nong","Mou","Chou","Yan", 393 "Li","Qiu","Li","Yu","Ping","Yong","Si","Feng","Qian","Ruo","Pai","Zhuo","Shu","Luo","Wo","Bi", 394 "Ti","Guan","Kong","Ju","Fen","Yan","Xie","Ji","Wei","Zong","Lou","Tang","Bin","Nuo","Chi","Xi", 395 "Jing","Jian","Jiao","Jiu","Tong","Xuan","Dan","Tong","Tun","She","Qian","Zu","Yue","Cuan","Di","Xi", 396 "Xun","Hong","Guo","Chan","Kui","Bao","Pu","Hong","Fu","Fu","Su","Si","Wen","Yan","Bo","Gun", 397 "Mao","Xie","Luan","Pou","Bing","Ying","Luo","Lei","Liang","Hu","Lie","Xian","Song","Ping","Zhong","Ming", 398 "Yan","Jie","Hong","Shan","Ou","Ju","Ne","Gu","He","Di","Zhao","Qu","Dai","Kuang","Lei","Gua", 399 "Jie","Hui","Shen","Gou","Quan","Zheng","Hun","Xu","Qiao","Gao","Kuang","Ei","Zou","Zhuo","Wei","Yu", 400 "Shen","Chan","Sui","Chen","Jian","Xue","Ye","E","Yu","Xuan","An","Di","Zi","Pian","Mo","Dang", 401 "Su","Shi","Mi","Zhe","Jian","Zen","Qiao","Jue","Yan","Zhan","Chen","Dan","Jin","Zuo","Wu","Qian", 402 "Jing","Ban","Yan","Zuo","Bei","Jing","Gai","Zhi","Nie","Zou","Chui","Pi","Wei","Huang","Wei","Xi", 403 "Han","Qiong","Kuang","Mang","Wu","Fang","Bing","Pi","Bei","Ye","Di","Tai","Jia","Zhi","Zhu","Kuai", 404 "Qie","Xun","Yun","Li","Ying","Gao","Xi","Fu","Pi","Tan","Yan","Juan","Yan","Yin","Zhang","Po", 405 "Shan","Zou","Ling","Feng","Chu","Huan","Mai","Qu","Shao","He","Ge","Meng","Xu","Xie","Sou","Xie", 406 "Jue","Jian","Qian","Dang","Chang","Si","Bian","Ben","Qiu","Ben","E","Fa","Shu","Ji","Yong","He", 407 "Wei","Wu","Ge","Zhen","Kuang","Pi","Yi","Li","Qi","Ban","Gan","Long","Dian","Lu","Che","Di", 408 "Tuo","Ni","Mu","Ao","Ya","Die","Dong","Kai","Shan","Shang","Nao","Gai","Yin","Cheng","Shi","Guo", 409 "Xun","Lie","Yuan","Zhi","An","Yi","Pi","Nian","Peng","Tu","Sao","Dai","Ku","Die","Yin","Leng", 410 "Hou","Ge","Yuan","Man","Yong","Liang","Chi","Xin","Pi","Yi","Cao","Jiao","Nai","Du","Qian","Ji", 411 "Wan","Xiong","Qi","Xiang","Fu","Yuan","Yun","Fei","Ji","Li","E","Ju","Pi","Zhi","Rui","Xian", 412 "Chang","Cong","Qin","Wu","Qian","Qi","Shan","Bian","Zhu","Kou","Yi","Mo","Gan","Pie","Long","Ba", 413 "Mu","Ju","Ran","Qing","Chi","Fu","Ling","Niao","Yin","Mao","Ying","Qiong","Min","Tiao","Qian","Yi", 414 "Rao","Bi","Zi","Ju","Tong","Hui","Zhu","Ting","Qiao","Fu","Ren","Xing","Quan","Hui","Xun","Ming", 415 "Qi","Jiao","Chong","Jiang","Luo","Ying","Qian","Gen","Jin","Mai","Sun","Hong","Zhou","Kan","Bi","Shi", 416 "Wo","You","E","Mei","You","Li","Tu","Xian","Fu","Sui","You","Di","Shen","Guan","Lang","Ying", 417 "Chun","Jing","Qi","Xi","Song","Jin","Nai","Qi","Ba","Shu","Chang","Tie","Yu","Huan","Bi","Fu", 418 "Tu","Dan","Cui","Yan","Zu","Dang","Jian","Wan","Ying","Gu","Han","Qia","Feng","Shen","Xiang","Wei", 419 "Chan","Kai","Qi","Kui","Xi","E","Bao","Pa","Ting","Lou","Pai","Xuan","Jia","Zhen","Shi","Ru", 420 "Mo","En","Bei","Weng","Hao","Ji","Li","Bang","Jian","Shuo","Lang","Ying","Yu","Su","Meng","Dou", 421 "Xi","Lian","Cu","Lin","Qu","Kou","Xu","Liao","Hui","Xun","Jue","Rui","Zui","Ji","Meng","Fan", 422 "Qi","Hong","Xie","Hong","Wei","Yi","Weng","Sou","Bi","Hao","Tai","Ru","Xun","Xian","Gao","Li", 423 "Huo","Qu","Heng","Fan","Nie","Mi","Gong","Yi","Kuang","Lian","Da","Yi","Xi","Zang","Pao","You", 424 "Liao","Ga","Gan","Ti","Men","Tuan","Chen","Fu","Pin","Niu","Jie","Jiao","Za","Yi","Lv","Jun", 425 "Tian","Ye","Ai","Na","Ji","Guo","Bai","Ju","Pou","Lie","Qian","Guan","Die","Zha","Ya","Qin", 426 "Yu","An","Xuan","Bing","Kui","Yuan","Shu","En","Chuai","Jian","Shuo","Zhan","Nuo","Sang","Luo","Ying", 427 "Zhi","Han","Zhe","Xie","Lu","Zun","Cuan","Gan","Huan","Pi","Xing","Zhuo","Huo","Zuan","Nang","Yi", 428 "Te","Dai","Shi","Bu","Chi","Ji","Kou","Dao","Le","Zha","A","Yao","Fu","Mu","Yi","Tai", 429 "Li","E","Bi","Bei","Guo","Qin","Yin","Za","Ka","Ga","Gua","Ling","Dong","Ning","Duo","Nao", 430 "You","Si","Kuang","Ji","Shen","Hui","Da","Lie","Yi","Xiao","Bi","Ci","Guang","Yue","Xiu","Yi", 431 "Pai","Kuai","Duo","Ji","Mie","Mi","Zha","Nong","Gen","Mou","Mai","Chi","Lao","Geng","En","Zha", 432 "Suo","Zao","Xi","Zuo","Ji","Feng","Ze","Nuo","Miao","Lin","Zhuan","Zhou","Tao","Hu","Cui","Sha", 433 "Yo","Dan","Bo","Ding","Lang","Li","Shua","Chuo","Die","Da","Nan","Li","Kui","Jie","Yong","Kui", 434 "Jiu","Sou","Yin","Chi","Jie","Lou","Ku","Wo","Hui","Qin","Ao","Su","Du","Ke","Nie","He", 435 "Chen","Suo","Ge","A","En","Hao","Dia","Ai","Ai","Suo","Hei","Tong","Chi","Pei","Lei","Cao", 436 "Piao","Qi","Ying","Beng","Sou","Di","Mi","Peng","Jue","Liao","Pu","Chuai","Jiao","O","Qin","Lu", 437 "Ceng","Deng","Hao","Jin","Jue","Yi","Sai","Pi","Ru","Cha","Huo","Nang","Wei","Jian","Nan","Lun", 438 "Hu","Ling","You","Yu","Qing","Yu","Huan","Wei","Zhi","Pei","Tang","Dao","Ze","Guo","Wei","Wo", 439 "Man","Zhang","Fu","Fan","Ji","Qi","Qian","Qi","Qu","Ya","Xian","Ao","Cen","Lan","Ba","Hu", 440 "Ke","Dong","Jia","Xiu","Dai","Gou","Mao","Min","Yi","Dong","Qiao","Xun","Zheng","Lao","Lai","Song", 441 "Yan","Gu","Xiao","Guo","Kong","Jue","Rong","Yao","Wai","Zai","Wei","Yu","Cuo","Lou","Zi","Mei", 442 "Sheng","Song","Ji","Zhang","Lin","Deng","Bin","Yi","Dian","Chi","Pang","Cu","Xun","Yang","Hou","Lai", 443 "Xi","Chang","Huang","Yao","Zheng","Jiao","Qu","San","Fan","Qiu","An","Guang","Ma","Niu","Yun","Xia", 444 "Pao","Fei","Rong","Kuai","Shou","Sun","Bi","Juan","Li","Yu","Xian","Yin","Suan","Yi","Guo","Luo", 445 "Ni","She","Cu","Mi","Hu","Cha","Wei","Wei","Mei","Nao","Zhang","Jing","Jue","Liao","Xie","Xun", 446 "Huan","Chuan","Huo","Sun","Yin","Dong","Shi","Tang","Tun","Xi","Ren","Yu","Chi","Yi","Xiang","Bo", 447 "Yu","Hun","Zha","Sou","Mo","Xiu","Jin","San","Zhuan","Nang","Pi","Wu","Gui","Pao","Xiu","Xiang", 448 "Tuo","An","Yu","Bi","Geng","Ao","Jin","Chan","Xie","Lin","Ying","Shu","Dao","Cun","Chan","Wu", 449 "Zhi","Ou","Chong","Wu","Kai","Chang","Chuang","Song","Bian","Niu","Hu","Chu","Peng","Da","Yang","Zuo", 450 "Ni","Fu","Chao","Yi","Yi","Tong","Yan","Ce","Kai","Xun","Ke","Yun","Bei","Song","Qian","Kui", 451 "Kun","Yi","Ti","Quan","Qie","Xing","Fei","Chang","Wang","Chou","Hu","Cui","Yun","Kui","E","Leng", 452 "Zhui","Qiao","Bi","Su","Qie","Yong","Jing","Qiao","Chong","Chu","Lin","Meng","Tian","Hui","Shuan","Yan", 453 "Wei","Hong","Min","Kang","Ta","Lv","Kun","Jiu","Lang","Yu","Chang","Xi","Wen","Hun","E","Qu", 454 "Que","He","Tian","Que","Kan","Jiang","Pan","Qiang","San","Qi","Si","Cha","Feng","Yuan","Mu","Mian", 455 "Dun","Mi","Gu","Bian","Wen","Hang","Wei","Le","Gan","Shu","Long","Lu","Yang","Si","Duo","Ling", 456 "Mao","Luo","Xuan","Pan","Duo","Hong","Min","Jing","Huan","Wei","Lie","Jia","Zhen","Yin","Hui","Zhu", 457 "Ji","Xu","Hui","Tao","Xun","Jiang","Liu","Hu","Xun","Ru","Su","Wu","Lai","Wei","Zhuo","Juan", 458 "Cen","Bang","Xi","Mei","Huan","Zhu","Qi","Xi","Song","Du","Zhuo","Pei","Mian","Gan","Fei","Cong", 459 "Shen","Guan","Lu","Shuan","Xie","Yan","Mian","Qiu","Sou","Huang","Xu","Pen","Jian","Xuan","Wo","Mei", 460 "Yan","Qin","Ke","She","Mang","Ying","Pu","Li","Ru","Ta","Hun","Bi","Xiu","Fu","Tang","Pang", 461 "Ming","Huang","Ying","Xiao","Lan","Cao","Hu","Luo","Huan","Lian","Zhu","Yi","Lu","Xuan","Gan","Shu", 462 "Si","Shan","Shao","Tong","Chan","Lai","Sui","Li","Dan","Chan","Lian","Ru","Pu","Bi","Hao","Zhuo", 463 "Han","Xie","Ying","Yue","Fen","Hao","Ba","Bao","Gui","Dang","Mi","You","Chen","Ning","Jian","Qian", 464 "Wu","Liao","Qian","Huan","Jian","Jian","Zou","Ya","Wu","Jiong","Ze","Yi","Er","Jia","Jing","Dai", 465 "Hou","Pang","Bu","Li","Qiu","Xiao","Ti","Qun","Kui","Wei","Huan","Lu","Chuan","Huang","Qiu","Xia", 466 "Ao","Gou","Ta","Liu","Xian","Lin","Ju","Xie","Miao","Sui","La","Ji","Hui","Tuan","Zhi","Kao", 467 "Zhi","Ji","E","Chan","Xi","Ju","Chan","Jing","Nu","Mi","Fu","Bi","Yu","Che","Shuo","Fei", 468 "Yan","Wu","Yu","Bi","Jin","Zi","Gui","Niu","Yu","Si","Da","Zhou","Shan","Qie","Ya","Rao", 469 "Shu","Luan","Jiao","Pin","Cha","Li","Ping","Wa","Xian","Suo","Di","Wei","E","Jing","Biao","Jie", 470 "Chang","Bi","Chan","Nu","Ao","Yuan","Ting","Wu","Gou","Mo","Pi","Ai","Pin","Chi","Li","Yan", 471 "Qiang","Piao","Chang","Lei","Zhang","Xi","Shan","Bi","Niao","Mo","Shuang","Ga","Ga","Fu","Nu","Zi", 472 "Jie","Jue","Bao",