unicode to ansi conversion  
Author Message
Maartin





PostPosted: Common Language Runtime, unicode to ansi conversion Top

Hi,
I have to convert a unicode-string into ansi-data.
I've found a way that works:
String UnicodeData = sourceReader.GetString(3);
IntPtr AnsiData = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(UnicodeData);
Byte[] bytes = new Byte[8192];
System.Runtime.InteropServices.Marshal.Copy(AnsiData, bytes, 0, 8192);
System.Runtime.InteropServices.Marshal.FreeHGlobal(AnsiData);

Is there a way to do this without using unmanaged memory


.NET Development15  
 
 
Mattias Sjogren





PostPosted: Common Language Runtime, unicode to ansi conversion Top

byte[] bytes = System.Text.Encoding.Default.GetBytes(UnicodeData);



 
 
Maartin





PostPosted: Common Language Runtime, unicode to ansi conversion Top

great, it works. Thanks