A sample code from msdn(Unicode to ASCII)
String^ unicodeString = "This string contains the unicode character Pi (\u03a0)";
// Create two different encodings.
Encoding^ ascii = Encoding::ASCII;
Encoding^ unicode = Encoding::Unicode;
// Convert the string into a byte array.
array<Byte>^unicodeBytes = unicode->GetBytes( unicodeString );
// Perform the conversion from one encoding to the other.
array<Byte>^asciiBytes = Encoding::Convert( unicode, ascii, unicodeBytes );
// Convert the new Byte into[] a char and[] then into a string.
array<Char>^asciiChars = gcnew array<Char>(ascii->GetCharCount( asciiBytes, 0, asciiBytes->Length ));
ascii->GetChars( asciiBytes, 0, asciiBytes->Length, asciiChars, 0 );
String^ asciiString = gcnew String( asciiChars );
// Display the strings created before and after the conversion.
Console::WriteLine( "Original String*: {0}", unicodeString );
Console::WriteLine( "Ascii converted String*: {0}", asciiString );
Please check the page:
http://msdn.microsoft.com/zh-tw/library/kdcak6ye%28v=vs.110%29.aspx
http://studio.wellwind.idv.tw/archives/197
沒有留言:
張貼留言