Unicode VS ANSI

zhaozj2021-02-16  92

I used to use this way. I didn't think about why I had to use it. I just met an article. I explained some content I used to be clearly clear, huh! It's been useful to me. I think big. If you are, you don't have to watch this article! The original text is as follows:

Unicode VS ANSI (Reposted from: Guangyu Garden)

*********************************************************** ****************************** Visual Basic 32-bit version of the string handle using Unicode, that is, the strings are in the VB It is stored in the format of Unicode. What is unicode? Simply put, every franchis is expressed in 2-byte, and each "physical word" is a "character". Therefore, Len ("Hello") The value returned by LEN ("ABC") is 3, because "Big" and "A" are a character. But this is handled for some Chinese characters, such as the information file of the pure text, is a big disaster, because you must locate each character with Byte, but Unicode has smashed everything. For example: LEN ("Good Morning") is transmitted 12, and LEN ("Today's weather is very good") Passing 6 For beginners, it is not easy to use VB to write the program is already a great thing, but immediately On the Chinese processing, I was a boring foot, and the blow was 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 is: StrConv (String, conversion format) where the conversion format is used here: vbunico converts the ANSI string to Unicodevbfromunicode to convert the Unicode string to ANSI to turn the string to ansi, All 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, Zhongshan Road Taipei 100, (02) 2345678" Debug.Print Len (sUnicode)' 44Debug.Print Mid Returns $ (Sunicode, 5, 10) 'Back A123456789Debug.print INSTR (SUNICODE, "Taipei")' Back 23 'Transfer Unicode string to ANSISANSI = STRCONV (SUNICODE, VBFROMUNICODE)' ANSI operation debug.print lenb ( Sansi) 'Back to 54debug.print Midb $ (Sansi, 8, 10)' Back ?????, because I forgot to Return to UnicodeBug.Print StrConv (MIDB $ (Sansi, 8, 10), vbunicode " Back to A123456789, please pay attention to the action of Unicode must do debug.print INSTRB (Sansi, StrConv ("Taipei", vbfromunicore) 'Back 23, don't forget to turn "Taipei" to ANSI, otherwise If you can't find the end sub [●] in the text file in VB, there is a fast reading method: private submmand1_click () Dim sfile as stringopen "c: /filename.txt" for Input as # 1sfile = INPUT $ (Lof (1), # 1) Close # 1END SUB but unfortunately, if you read the archive in the case, the above section will appear in the error. Because the LOF is transmitted back the number of files, the input is read by the file, which is in Chinese, so that the number of characters in the file will be less than the BYTE number, 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 stringopen "c: /filename.txt" for input as # 1sfile = strconv (INPUTB $ (Lof) 1), # 1), Vbunicode) Close # 1) The above correction program first reads the files in the file, but the file read in INPUTB is an ANSI format, so you have to use StrConv to Unicode. [●] Random data files Many text files are in the position of the fixed position group, such as the following data format: Wang Xiaomin 650110 Taipei Zhongshan Road No. 100 (02) 1234567 Zhang Daxie 660824 Hualie County Dajia Town Guangdong No. 23 (03) 9876543 ... how to handle this type of file? This is necessary to use Type and byte Array.

转载请注明原文地址:https://www.9cbs.com/read-14143.html

New Post(0)