Implementation Code of vbs to solve TXT text data processing problems

Source: Internet
Author: User

There is a small problem, as shown below:
The hosts file 1.txt is available, and the content is as follows:
Occurrence Frequency of numerical value 1: 12647
Occurrence Frequency of numeric _ 2: 10000
Occurrence Frequency of value _ 3: 12608
Occurrence Frequency: 8712
Occurrence Frequency: 10658
Occurrence Frequency of value 6: 8472
Occurrence Frequency of numeric value 7: 11232
Occurrence Frequency of numerical value _ 8: 8648
Occurrence Frequency of numerical value 9: 9264
Occurrence Frequency of numerical value _ 10: 7192
Occurrence Frequency of numeric _ 11: 7192
....
There are about 100 rows
It is required to put the values of each row in the variable and then output them to the text file 2.txt.
For example, place 12674 of the first row in the variable A1.
Put 10000 of the second row in variable a2
Put 12608 of the third row in variable a2
.... Until the last line
The final output text file is:
A1 = 12647
A2 = 10000.
A3 = 12608
A4 = 8712
....
A11 = 7192
Hope you can find the relevant code and run it in windows !! Find and find ..
The implementation code is as follows::
VB code: Copy codeThe Code is as follows: set fso = createobject ("scripting. filesystemobject ")
Set file = fso. opentextfile ("1.txt ")
Ts = file. readall
File. close
Set fil = fso. createtextfile ("2.txt ")
Ts = replace (ts, "value _", "")
Ts = replace (ts, "occurrence frequency", "= ")
'''Comment out the comment if there are horizontal lines and empty lines.
Ts = replace (ts, "-----------------------" + vbnewline ,"")
Fil. write ts
Fil. close
MsgBox "processed" completes the code of converting 1.txtto 2.txt directly, and the intermediate variable a1 ~ A100it saves time. If you still need the intermediate variable for other purposes, you can read the 2.txt content and assign a value. The Code is as follows:
VBScript code:
Set fso = createobject ("scripting. filesystemobject ")
Set ts = fso. opentextfile ("2.txt ")
I = 0
Do while ts. AtEndOfStream = false
Str = ts. ReadLine
Execute str 'execute assignment
I = I + 1
Execute ("value = a" & I) 'to get the variable a1 ...... Value
Response. Write ("a" & I & "value:" & value & "<br/>") 'output
Loop has another method, as shown in the following code:
VBScript code:
Set fs = CreateObject ("Scripting. FileSystemObject ")
Set txt1 = fs. OpenTextFile ("1.txt", 1)
Set txt2 = fs. CreateTextFile ("C: \ FSO \ ScriptLog.txt ")
Do Until txt1.AtEndOfStream
Str_a = txt1.ReadLine
Str_a = replace (str_a, "degree", "$ ")
Str_ar = split (str_a, "$ ")
If isnumeric (str_ar (ubound (str_a) then
Txt2.writeline str_ar (ubound (str_a ))
End if
Loop
Txt1.close
Txt2.close
Set txt1 = nothing
Set txt2 = nothing
Set fs = nothing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.