解决WEB页的中英文显示问题
WEB页的中英文显示解决方案之一:
protected string EncodingCoverter(string text, int sourceCodePage, int targetCodePage)
{
// Gets the encoding for the specified code page.
Encoding sourceEncoding = Encoding.GetEncoding(sourceCodePage);
Encoding targetEncoding = Encoding.GetEncoding(targetCodePage);
return EncodingCoverter(text, sourceEncoding, targetEncoding);
}
protected string EncodingCoverter(string text, Encoding sourceEncoding, Encoding targetEncoding)
{
// Gets the byte representation of the specified string.
byte[] decodedChars = sourceEncoding.GetBytes(text);
string encodedString = targetEncoding.GetString(decodedChars);
return encodedString;
}
{
// Gets the encoding for the specified code page.
Encoding sourceEncoding = Encoding.GetEncoding(sourceCodePage);
Encoding targetEncoding = Encoding.GetEncoding(targetCodePage);
return EncodingCoverter(text, sourceEncoding, targetEncoding);
}
protected string EncodingCoverter(string text, Encoding sourceEncoding, Encoding targetEncoding)
{
// Gets the byte representation of the specified string.
byte[] decodedChars = sourceEncoding.GetBytes(text);
string encodedString = targetEncoding.GetString(decodedChars);
return encodedString;
}
Encoding sourceEncoding = Encoding.GetEncoding(1252);
Encoding targetEncoding = Encoding.GetEncoding(936);
Encoding targetEncoding = Encoding.GetEncoding(936);