Simplified and traditional webpage Conversion

Source: Internet
Author: User
Using system;
Using system. text;
Using system. Text. regularexpressions;
Using system. IO;
Using system. Web;
Namespace dreamzone. Core
{
/// <Summary>
/// Summary of 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 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)
{// Convert traditional to simplified
Return (Microsoft. VisualBasic. Strings. strconv (STR, Microsoft. VisualBasic. vbstrconv. simplifiedchinese, 0 ));

}
Public String simplified2traditional (string Str)
{// Convert simplified to traditional Chinese
Return (Microsoft. VisualBasic. Strings. strconv (STR as string, Microsoft. VisualBasic. vbstrconv. traditionalchinese, 0 ));

}
# Endregion
}
}

Only one line of code is required for calling:


Response. Filter = new dreamzone. Core. cg2bfilter (response. Filter); // you can specify a filter.

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.