This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string ChangeEncoding(Encoding encFrom, Encoding encTo, string srcStr) | |
{ | |
// Convert the string into a byte[]. | |
byte[] fromBytes = encFrom.GetBytes(srcStr); | |
// Perform the conversion from one encoding to the other. | |
byte[] toBytes = Encoding.Convert(encFrom, encTo, fromBytes); | |
// Convert the new byte[] into a char[] and then into a string. | |
// This is a slightly different approach to converting to illustrate | |
// the use of GetCharCount/GetChars. | |
char[] toChars = new char[encTo.GetCharCount(toBytes, 0, toBytes.Length)]; | |
encTo.GetChars(toBytes, 0, toBytes.Length, toChars, 0); | |
return new string(toChars); | |
} |
No comments:
Post a Comment