[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

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 包爾伯 的頭像
    包爾伯

    人生過程精彩才是重點

    包爾伯 發表在 痞客邦 留言(0) 人氣()