[C#]
#region 轉換BIG5
/// <summary>
/// 轉換BIG5
/// </summary>
/// <param name=”strUtf”>輸入UTF-8</param>
/// <returns></returns>
public string ConvertBig5(string strUtf)
{
Encoding utf81 = Encoding.GetEncoding(”utf-8″);
Encoding big51 = Encoding.GetEncoding(”big5″);
Response.ContentEncoding = big51;
byte [] strUtf81 = utf81.GetBytes(strUtf.Trim());
byte [] strBig51 = Encoding.Convert(utf81, big51, strUtf81);
char[] big5Chars1 = new char[big51.GetCharCount(strBig51, 0, strBig51.Length)];
big51.GetChars(strBig51, 0, strBig51.Length, big5Chars1, 0);
string tempString1 = new string(big5Chars1);
return tempString1;
}
#endregion
[VB]
Public Function ConvertBig5(ByVal strUtf As String) As String
Dim utf81 As Encoding = Encoding.GetEncoding(”utf-8″)
Dim big51 As Encoding = Encoding.GetEncoding(”big5″)
Response.ContentEncoding = big51
Dim strUtf81 As Byte() = utf81.GetBytes(strUtf.Trim())
Dim strBig51 As Byte() = Encoding.Convert(utf81, big51, strUtf81)
Dim big5Chars1 As Char() = New Char(big51.GetCharCount(strBig51, 0, strBig51.Length) - 1) {}
big51.GetChars(strBig51, 0, strBig51.Length, big5Chars1, 0)
Dim tempString1 As New String(big5Chars1)
Return tempString1
End Function
留言列表