It seems that you're writing using UTF-16 and reading using UTF-8 (or UTF-7 or ASCII). Review your code and keep the same encoding when accesing the same data.
Regards.
"kenny" <
[email protected]> escribió en el mensaje | If I use unicode encoding then all characters are displayed correcty but
| there are too much null bytes between them.
| Example:
| normal: S c h l i e ß e n
|
| modified: S c h l i e ß e n
|
| "José Manuel Agüero" wrote:
|
| > It doesn't exist such thing as writing a file with independence from the encoding. A file holds binary data. How that data represents text characters or other things depends on the encoding you select.
| > What exactly do you want to do? Write and read text in a file? Serialize objects? Write and read binary data?
| >
| > By the way, OpenTextFileWriter defaults to ASCII encoding. You may use OpenTextFileWriter("test.uni", True, System.Text.Encoding.Unicode) to be able to store all characters.
| >
| > Regards.
| >
| >
| > "kenny" <
[email protected]> escribió en el mensaje | > | No, it is UTF-8...but there are also other characters...not only unicode. Is
| > | there a way to write them to a file independent from the encoding?? I tried
| > | BinaryWriter but it seems also to need an encoding specified to write
| > | correctly. I just want to write any data to a file....
| > |
| > | "José Manuel Agüero" schrieb:
| > |
| > | > Hello kenny,
| > | >
| > | > Your string seems to represent UTF-16 encoded characters, but you are converting somehow as if it was UTF-8.
| > | > Your code should look like this:
| > | >
| > | > Dim intIndex As Integer
| > | > Dim b() As Byte
| > | > Dim s As String
| > | > Dim file As System.IO.StreamWriter
| > | >
| > | > ReDim b(Len(outputhex) \ 2)
| > | > For intIndex = 1 To Len(outputhex) Step 2
| > | > b(intIndex \ 2) = Convert.ToByte(Mid(outputhex, intIndex, 2), 16)
| > | > Next
| > | > s = System.Text.Encoding.Unicode.GetString(b)
| > | >
| > | > file = My.Computer.FileSystem.OpenTextFileWriter("test.uni", True)
| > | > file.Write(s)
| > | > file.Close()
| > | >
| > | > Regards.
| > | >
| > | >
| > | > "kenny" <
[email protected]> escribió en el mensaje | > | > |I have a String outputhex which consists of unicodetext translated into hex.
| > | > | example: test = 7400650073007400
| > | > |
| > | > | now i translate each two characters of the hexstring (outputhex) into byte
| > | > | and then into chars. but this is the point where something is wrong...
| > | > | (having the byteorder mark removed would also be very good)
| > | > |
| > | > | "Schließen" gets to "Schlie鿃攀渀" and so on...
| > | > |
| > | > |
| > | > |
| > | > | Here is the code:
| > | > |
| > | > | Dim intIndex As Short
| > | > | Dim j As Integer
| > | > | Dim ch As Char
| > | > |
| > | > | Dim file As System.IO.StreamWriter
| > | > | file = My.Computer.FileSystem.OpenTextFileWriter("test.uni", True)
| > | > |
| > | > | For intIndex = 1 To Len(outputhex) Step 2
| > | > | j = CByte("&H" & Mid(outputhex, intIndex, 2))
| > | > | ch = Convert.ToChar(j)
| > | > | file.Write(ch)
| > | > | Next
| > | > |
| > | > | file.Close()
| > | > |
| > | > |
| > | > |
| > | > |
| > | > | Thanks for the help, its urgent
| >
| >