ASCII字串解碼,比如Ӓӓ
阿新 • • 發佈:2018-12-09
用正則分別解碼字串裡可以解碼的ASCII字元 |
/// <summary> /// ASCII解碼 /// </summary> /// <param name="str">需要解碼的字串</param> /// <returns></returns> public static string ToAsciiIDecode(this string str) { StringBuilder sb = new StringBuilder(); int indexSatae = -1; foreach (Match i in new Regex(@"&#\d{1,5};").Matches(str)) { string s = i.Value.Substring(2); sb.Append((char)(s.Substring(0,s.Length-1).toInt())); if (indexSatae != -1) { sb.Append(str.Substring(indexSatae, i.Index - indexSatae)); } indexSatae = i.Index + i.Length; } if (indexSatae != -1) { sb.Append(str.Substring(indexSatae)); } return sb.ToString(); } /// <summary> /// 轉換成Int型別 /// </summary> /// <param name="str">需要轉換的字串</param> /// <returns></returns> public static int toInt(this string str) { return int.Parse(str); }