The first way to use C # 's own method encoding:
public string Convencode (string write,string fromencode,string Toencode)
{
Declaring a character set
Encoding from,to;
From = Encoding.GetEncoding (Fromencode);
to = Encoding.GetEncoding (Toencode);
byte[] temp = from.getbytes (write);
byte[] Temp1 = Encoding.convert (from,to,temp);
Returns the converted character
Return to.getstring (TEMP1);
}
The second way to invoke the MultiByteToWideChar method of C + + is
[DllImport ("kernel32.dll")]
public static extern int MultiByteToWideChar (int CodePage, int dwflags,string lpmultibytestr,
int Cchmultibyte, [MarshalAs (UNMANAGEDTYPE.LPWSTR)]string lpwidecharstr, int cchwidechar);
public string Mbytetowchar (String Content,int toencode)
{
Character encoding conversion gb2312:936 utf-8:65001 big5:950 latin1:1252
int len = Pinvoke.multibytetowidechar (toencode,0,content,-1,null,0);
char[] temp = new Char[len];
String content1 = new String (temp);
Pinvoke.multibytetowidechar (Toencode,0,content,-1,content1,len);
return content1;
}