VBS solves the problem of txt text data related problems implementation code _vbs

Source: Internet
Author: User
Tags readline
There is a small problem, as follows
The existing text file, 1.txt, reads as follows:
Numerical _1 appears frequency 12647
Numerical _2 appears frequency 10000
Numerical _3 appears frequency 12608
Numerical _4 appears frequency 8712
Numerical _5 appears frequency 10658
Numerical _6 appears frequency 8472
Numerical _7 appears frequency 11232
Numerical _8 appears frequency 8648
Numerical _9 appears frequency 9264
Numerical _10 appears frequency 7192
Numerical _11 appears frequency 7192
。。。。
It's about 100 lines.
Requires that the values in each row of the inside be placed in a variable and then exported to a text file 2.txt
For example: Put 12674 of the first row into the variable A1
Put 10000 of the second row into the variable A2.
Put 12608 of the third row into the variable A2.
... until the last line.
The final output to the "2.txt" text file reads:
A1 = 12647
A2 = 10000
A3 = 12608
a4 = 8712
....
A11 = 7192
Hope to be able to find the relevant code, and can be run under windows!! Find AH find ah ah.
The implementation code is as follows
VB Code:
Copy Code code 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 _", "a")
Ts=replace (TS, "Occurrence frequency", "=")
"If there is a horizontal line and a blank row, plus this, no comment out
Ts=replace (ts, "-----------------------" +vbnewline+vbnewline, "")
Fil.write TS
Fil.close
MsgBox "Processing Complete" above the code is the 1.txt directly to 2.txt, intermediate variable a1~a100 omitted, if you also need intermediate variables for other purposes, you can read 2.txt content and assign values, 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 ' performs assignment
I=i+1
Execute ("value=a" & i) ' gets the variable A1 ... The value
Response.Write ("A" & I & "value is:" & Value & "<br/>") ' Output
Loop also has a 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, "degrees", "$")
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.