12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace Admin.Core.Common.Helpers
- {
- public static class UnicodeHelper
- {
-
-
-
-
-
- public static string StringToUnicode(string value)
- {
- byte[] bytes = Encoding.Unicode.GetBytes(value);
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < bytes.Length; i += 2)
- {
-
- stringBuilder.AppendFormat("u{0}{1}", bytes[i + 1].ToString("x").PadLeft(2, '0'), bytes[i].ToString("x").PadLeft(2, '0'));
- }
- return stringBuilder.ToString();
- }
-
-
-
-
-
- public static string UnicodeToString(string unicode)
- {
- unicode = unicode.Replace("%", "\\");
- return new Regex(@"\\u([0-9A-F]{4})", RegexOptions.IgnoreCase | RegexOptions.Compiled).Replace(
- unicode, x => string.Empty + Convert.ToChar(Convert.ToUInt16(x.Result("$1"), 16)));
- }
- }
- }
|