In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use vbs to solve problems related to TXT text data, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
There is a small problem, as follows:
The existing text file, 1.txt, contains the following:
The occurrence frequency of the value _ 1 is 12647
The occurrence frequency of the value _ 2 is 10000
The occurrence frequency of the value _ 3 is 12608
The occurrence frequency of the value _ 4 is 8712
The occurrence frequency of the value _ 5 is 10658
The occurrence frequency of the value _ 6 is 8472
The occurrence frequency of the value _ 7 is 11232.
The occurrence frequency of the value _ 8 is 8648
The occurrence frequency of the value _ 9 is 9264
The occurrence frequency of the value _ 10 is 7192
The occurrence frequency of the value _ 11 is 7192.
.
It's about 100 lines.
It is required to put the value of each line into a variable and then output it into a text file 2.txt
For example: put 12674 of the first line in the variable A1
Put 10000 of the second line in the variable a2.
Put 12608 of the third line in the variable a2.
... . Until the last line.
The final output to the "2.txt" text file is:
A1 = 12647
A2 = 10000
A3 = 12608
A4 = 8712
... .
A11 = 7192
Hope to be able to find the relevant code, and can run under windows! Look for it.
The implementation code is as follows:
VB code:
The copy 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, "numeric _", "a")
Ts=replace (ts, "occurrence frequency", "=")
If there are dashes and blank lines, plus this, comment out if there is no
Ts=replace (ts, "- -" + vbnewline+vbnewline, "")
Fil.write ts
Fil.close
The above code of MsgBox "processing complete" changes 1.txt directly to 2.txt, leaving out the intermediate variable a1~a100. If you need the intermediate variable for other purposes, you can read the 2.txt content and assign a value as follows:
VBScript code:
Set fso = createobject ("scripting.filesystemobject")
Set ts = fso.opentextfile ("2.txt")
ITunes 0
Do while ts.AtEndOfStream=false
Str = ts.ReadLine
Execute str 'performs assignment
I=i+1
Execute ("value=a" & I) 'gets the variable A1... Value of
Response.Write ("a" & I & "value is: & value &") 'output
There is another method for loop, 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
Thank you for reading this article carefully. I hope the article "how to use vbs to solve the problems related to TXT text data" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.