C # implement simplified and Traditional Chinese Interchange

Source: Internet
Author: User
Using System;
Using System. text;
Using System. Text. regularexpressions;
Using System. IO;
Using System. Web;

//


// cg2bfilter summary
///
Public class cg2bfilter: stream
{< br> stream responsestream;
long position;
stringbuilder responsehtml;

Public cg2bfilter (Stream inputstream)
{< br> responsestream = inputstream;
responsehtml = New stringbuilder ();
}

# region filter overrides
Public override bool Canread
{< br> Get { return true ;}< BR >}

Public override bool canseek
{< br> Get { return true ;}
}

Public override bool canwrite
{< br> Get { return true ;}
}

Public Override VoidClose ()
{
Responsestream. Close ();
}

Public Override VoidFlush ()
{
Responsestream. Flush ();
}

Public override long length
{< br> Get { return 0 ;}
}

Public override long position
{< br> Get { return position ;}
set {position = value ;}
}

Public override long seek ( long offset, seekorigin origin)
{< br> return responsestream. seek (offset, origin);
}

Public override void setlength ( long length)
{< br> responsestream. setlength (length);
}

Public Override IntRead (Byte[] Buffer,IntOffset,IntCount)
{
ReturnResponsestream. Read (buffer, offset, count );
}
# Endregion

# Region Conversion task
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 custom functions
Public string traditional2simplified ( string Str)
{< br> return (Microsoft. visualBasic. strings. strconv (STR, Microsoft. visualBasic. vbstrconv. simplifiedchinese, 0 ));

}
Public StringSimplified2traditional (StringStr)
{
Return(Microsoft. VisualBasic. Strings. strconv (StrAsString, Microsoft. VisualBasic. vbstrconv. traditionalchinese,0));

}
# Endregion

// response. filter = new cg2bfilter (response. filter); In Aspx. call
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.