繁體解決方案,dotNet開發專用。

來源:互聯網
上載者:User

參考:http://blog.csdn.net/superdullwolf/archive/2006/12/15/1443596.aspx

。Net做這個就容易多了,重寫Filter類就可以了。

用法:

 if(Session["big5"].ToString()=="2"){Response.Filter = new DreamZone.Core.CG2BFilter(Response.Filter);}
  

CG2BFilter.cs檔案如下:

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
namespace DreamZone.Core
{
 /// <summary>
 /// CG2BFilter 的摘要說明。
 /// </summary>
  
  public class CG2BFilter : Stream
  {
   Stream          responseStream;
   long            position;
   StringBuilder   responseHtml;

   public CG2BFilter (Stream inputStream)
   {
    responseStream = inputStream;
    responseHtml = new StringBuilder ();
   }

   #region Filter overrides
   public override bool CanRead
   {
    get { return true;}
   }

   public override bool CanSeek
   {
    get { return true; }
   }

   public override bool CanWrite
   {
    get { return true; }
   }

   public override void Close()
   {
    responseStream.Close ();
   }

   public override void Flush()
   {
    responseStream.Flush ();
   }

   public override long Length
   {
    get { return 0; }
   }

   public override long Position
   {
    get { return position; }
    set { position = value; }
   }

   public override long Seek(long offset, SeekOrigin origin)
   {
    return responseStream.Seek (offset, origin);
   }

   public override void SetLength(long length)
   {
    responseStream.SetLength (length);
   }

   public override int Read(byte[] buffer, int offset, int count)
   {
    return responseStream.Read (buffer, offset, count);
   }
   #endregion

   #region 轉換任務
   public override void Write(byte[] buffer, int offset, int count)
   {
     string strBuffer = System.Text.UTF8Encoding.UTF8.GetString (buffer, offset, count);
     string  finalHtml = Simplified2Traditional(strBuffer);    
     byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes (finalHtml);       
     responseStream.Write (data, 0, data.Length);           
      
   }

   #endregion
#region 自訂函數
   public  string Traditional2Simplified( string str)
   { //繁體轉簡體
    return(Microsoft.VisualBasic.Strings.StrConv(str, Microsoft.VisualBasic.VbStrConv.SimplifiedChinese,0));
   
   }
   public  string Simplified2Traditional( string str)
   { //簡體轉繁體
    return(Microsoft.VisualBasic.Strings.StrConv(str as String, Microsoft.VisualBasic.VbStrConv.TraditionalChinese,0));
  
   }
 #endregion
  }
}
 
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.