Home > Software engineering > About VB garbled words after the modification of text file contents.
About VB garbled words after the modification of text file contents.
Time:09-24
Private Sub Command2_Click () Open "D: \ sheji1 \ script1 variable changes. TXT" For Input As # 1 The Do While Not EOF (1) The Line Input # 1, STRTXT If InStr (STRTXT, "outside the core radius") Then STRTXT=Replace (STRTXT, "outside the core radius, Text1. Text) End the If S=s & amp; STRTXT & amp; VbCrLf Loop Close # 1 Open "D: \ sheji1 \ script1 variable to modify 2. TXT" For the Output As the # 1 Print # 1, s; Close # 1 End Sub Code as above, replace with input to the value in TEXT1 "outside the core radius" of the text file, But after open the written text files found Chinese place all the code, but if the core outer radius of the variable characters such as CXWBJ instead, can replace the success, is this why?
CodePudding user response:
This is because the code is not Unicode text file
CodePudding user response:
In a binary way access to try...
CodePudding user response:
Yes, Open For Open the Output this way, to Print Output text, use the Windows should be the default character encoding (in simplified Chinese Windows are generally GBK) of the Output, it seems that you of the existing "script1 variable to modify 2. TXT" is not using the default encoding,
CodePudding user response:
That I how to modify the code?
CodePudding user response:
I also want to know, I also encountered similar problems!
CodePudding user response:
Give you a reference example, consider the modified into your own,
Function ReadBinaryText (ByVal bFile As String) As String "' read text files On Error GoTo 100 Dim iNum As an Integer, v As the Variant INum=FreeFile () The Open bFile For Binary As # iNum The Get iNum, # 1, v Close # iNum ReadBinaryText=v The Exit Function 100: MsgBox Err. The Description End the Function Sub SaveTextFile (ByVal bFile As String, ByVal bValue As String) 'to write text file On Error GoTo 100 Dim iNum As an Integer, v As the Variant, Byt () As Byte INum=FreeFile () The Open bFile For Binary As # iNum Byt=bValue V=Byt Put iNum, # 1, v Close # iNum The Exit Sub 100: MsgBox Err. The Description End Sub
Writing files, if the new content, shorter than the original, the original file spare parts will not be deleted, although does not affect the reading, but affects the size of the file, So, if you mind this, write files if there are deleted before...
CodePudding user response:
I have a place wrong, VB it save text files are ANSI format, I want to modify the VBS file is utf-8, Chinese characters is in the file, and after the modification, is want to save the original VBS file don't garbled words, is still a utf-8 documents, too sad, find ways to find on the Internet for several days, can read the relevant examples, but change is always up, under the ace to give directions? Best can help me to modify it,