![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
-----Original Message----- "a52" <wabnel (AT) hotmail (DOT) com> wrote in message news:0c2c01c3d5f8$f0c5b3c0$a401280a (AT) phx (DOT) gbl... Hello. I have a problem working with file with VB.NET. I consurting a DataBase, de Data have special caracters (ñ, Ñ, etc). When I try to save the file as ASCII File this characters changed by others. snip Only the UTF8 file have the data fine, the ASCII changed don't now why. How can I Make a ASCII file with fine data? please help me. Checking the help in Visual Studio .NET, under the Encoding class, there is an example of converting from Unicode to ASCII. The supplied code may help you. [Visual Basic] Imports System Imports System.Text Namespace Convert_Example Class MyConvertExampleClass Shared Sub Main() Dim unicodeString As String = "This string contains the unicode character Pi(Ð)" ' Create two different encodings. Dim ascii As Encoding = Encoding.ASCII Dim [unicode] As Encoding = Encoding.Unicode ' Convert the string into a byte[]. Dim unicodeBytes As Byte() = [unicode].GetBytes(unicodeString) ' Perform the conversion from one encoding to the other. Dim asciiBytes As Byte() = Encoding.Convert ([unicode], ascii, unicodeBytes) ' 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. Dim asciiChars(ascii.GetCharCount (asciiBytes, 0, asciiBytes.Length)) As Char ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0) Dim asciiString As New String(asciiChars) ' Display the strings created before and after the conversion. Console.WriteLine("Original string: {0}", unicodeString) Console.WriteLine("Ascii converted string: {0}", asciiString) End Sub End Class End Namespace Of course, if your source contains characters that are not in the ASCII character set, a "fine" conversion is not possible. I recommend that you read the help article on the Encoding class, especially the parts on what characters can be converted. -- Peter [MVP Academic] . |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |