43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Mini.Common
|
|
{
|
|
public static class CommpnHelpEx
|
|
{
|
|
/// <summary>
|
|
/// unicode编码
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
/// <returns></returns>
|
|
public static string ToUnicodeString(this string str)
|
|
{
|
|
StringBuilder strResult = new StringBuilder();
|
|
if (!string.IsNullOrEmpty(str))
|
|
{
|
|
for (int i = 0; i < str.Length; i++)
|
|
{
|
|
strResult.Append("\\u");
|
|
strResult.Append(((int)str[i]).ToString("x"));
|
|
}
|
|
}
|
|
return strResult.ToString();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// unicode解码
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
/// <returns></returns>
|
|
public static string FromUnicodeString(this string str)
|
|
{
|
|
if (string.IsNullOrEmpty(str))
|
|
return str;
|
|
return System.Text.RegularExpressions.Regex.Unescape(str);
|
|
}
|
|
}
|
|
}
|