Home > Software engineering >  Vb to read unicode gibberish
Vb to read unicode gibberish

Time:10-02

? Hola! No is a Spanish
? Hola! No save. TXT encoded as unicode, test the following code, shown or not correct!

 Dim textBytes () As Byte, headBytes (2) the As Byte 
Fn=App. Path & amp; "\ test. TXT"
If Dir (fn)="" Then
MsgBox "file does not exist, please click on" write "button to generate" MyUnicode. TXT "file", vbInformation
The Exit Sub
End the If
The Open fn For Binary As # 1
Get # 1, and headBytes () 'read the file header,
Close # 1
If headBytes (0)=255 And headBytes (1)=254 Then 'is Unicode, hex is: FF, FE,
The Open fn For Binary As # 1
ReDim textBytes (LOF (1) - (2) '2 bytes occupied minus the file header,
Get the # 1, 3, textBytes () 'third byte to text content,
Close # 1
Text1. Text=textBytes () 'in VB is a UniCode string format, so direct assignment UniCode code can display Text content,
RichTextBox1. Text=textBytes ()
The Else
MsgBox "Unicode, will not be read, please click the" write "button,", vbInformation
End the If

CodePudding user response:

Should remember correctly, the third byte index is 2
Get the # 1, 3, textBytes () 'third byte to text content,

CodePudding user response:

, shown as the code is to prove your control does not support Unicode characters display! With Microsoft Forms 2.0 Object Library TextBox controls give it a try,

CodePudding user response:

Tested this code on my machine completely true,

CodePudding user response:

Test your Spanish, garbled, could be control is too old, do not support the new characters, some of the font is not displayed correctly,

Characters such as the euro, some old program is to display,

CodePudding user response:

Like this character, if you stick to vb Exe is garbled, so you in any way to read a file to display to the text, he also must be garbled,

I tried 6, 7 kinds of fonts, didn't also found not gibberish,

Stick to the vc exe, was entirely normal,

CodePudding user response:

reference 1st floor bcrun response:
remember correctly, the third byte index should be 2
Get the # 1, 3, textBytes () 'third byte to text content,


Correct once, then verified, 3 is 3 bytes,
You this not GBK character, can't normal in VB6 and bring the ANSI version control display is very normal, estimates that you are using is Chinese WINDOWS system, thought the building should be VB.NET, after you to UNICODE as the important content of the program, just write by VB.NET directly

CodePudding user response:

You replace language library a try,
  • Related