The string processing of the Unicode and ANSI format Visual Basic 32-Bit version of Visual Basic 32-bit version of the Visual Basic 32-Bit version is stored in the format of Unicode in the VB. What is unicode? Simply put, every character is expressed in the form of 2-byte, and each "entity character" is a "character". Therefore, the value returned by LEN ("Good") is 3 because "Big" and "A" are a character. But this is handled for some Chinese characters, such as pure text data files, is a big disaster, because you must locate each character with Byte, but Unicode has smashed everything. For example: LEN ("Good Morning") returns 12, and Len ("Today's weather is very good") Back to 6 for beginners, it is hard to write the program, but it is right in Chinese. The handling of a boring foot is handled, and the blow is not small. But don't be afraid, in fact, as long as you know more about some instructions, you can solve the problem of Chinese processing. What is the instruction? The most important thing is that StrConv is. The StrConv function syntax is: strConv (string to be converted, conversion format) where the conversion format is hereby converted to UnicodeVbFromunicode to ANSI to convert the Unicode string to ansi after converting a string to ANSI, all The string processing instructions must be added B, for example: Leftb, Rightb, MIDB, ChRB, INSTRB, LENB, INPUTB, etc. Use these instructions to handle it. When you have finished processing, you can turn it back to Unicode so you can use a general string to handle instructions. Do you understand this? If you still don't understand, look at the example below: Simple use Example See the basic example below you should have some concepts for the string of VB.
Private Sub Command1_Click () Dim sUnicode As StringDim sAnsi As String 'Unicode operation sUnicode = "Xiaoming, A123456789,651023, Shanghai Zhongshan Road 100, (02) 2345678" Debug.Print Len (sUnicode)' returns 44Debug.Print Mid $ (Sunicode, 5, 10) 'Return A123456789Debug.print INSTR (SUNICODE, "Shanghai")' Return 23 'to transfer Unicode strings to Ansisansi = strconv (SUNICODE, VBFROMUNICODE)' ANSI operation debug.print lenb (sansi) ' Returns 54Debug.print MIDB $ (Sansi, 8, 10) 'Return ?????, because I forgot to go back to UnicodeBug.Print StrConv (MIDB $ (Sansi, 8, 10), vbunicode)' Return to A123456789, please pay attention to Back to Unicode's action must be Debug.Print INSTRB (Sansi, StrConv ("Shanghai", vbfromunicode)) 'Return 23, don't forget to turn "Shanghai" to ANSI, otherwise you will not find end Sub read In the tip of the text file in VB, there is a quick reading file: private submmand1_click () Dim sfile as string open "c: /filename.txt" for Input as # 1sfile = INPUT $ (Lof (1), # 1) Close # 1END SUB but very unfortunately if you read the file containing the Chinese word, then this program will have an error in Input Pastend Of File. Because LOF returns the number of files, the input function reads the number of characters. Since the file contains Chinese, the number of characters in the file will be less than the number of BYTE, so there is an error. To solve this problem, we have to use two functions of strConv and inputb: private submmand1_click () Dim sfile as string open "c: /filename.txt" for input as # 1sfile = strconv (INPUTB $ (Lof) 1), # 1), the case. The following correction program first reads the file with INPUTB, but the file read in INPUTB is an ANSI format, so you have to transfer it with StrConv to Unicode. Random data files Many text data files are classified in a fixed byte, such as the following data format: Wang Xiaomin 650110 Shanghai Zhongshan Road No. 100 (02) 1234567 Zhang Daxie 660824 Jiaolian County Dajia Town Guangdong Street 23 03) 9876543 ... How to deal with this type of file? This is necessary to use Type and byte Array.