VBScript读取特定行并提取字符并将其存储为变量 [英] VBScript to read specific line and extract characters and store it as a variable
问题描述
我有一个VB脚本从文本文件中读取第11行。但是从那行,我需要提取字符48到53并将其保存为一个变量。完成后,我想使用该变量,并在Web网址中使用它。示例如下:
I have a VB script that reads the 11th line from a text file. However from that line I need to extract characters 48 through 53 and save it as a variable. After this is accomplished I would like to use that variable and use it in a web url. Example below:
szCPUSer.dat文件的内容如下所示:
Contents of the szCPUSer.dat file look like this:
脚本我已读取第10行
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("szCPUSer.dat", ForReading)
For i = 1 to 10
objTextFile.ReadLine
Next
strLine = objTextFile.ReadLine
Wscript.Echo strLine
objTextFile.Close
我需要脚本从第11行提取03187将其存储为变量SerNum。之后我想使用在URL中提取的数字,例如:
I need the script to extract 03187 from the 11th line than store it as a variable SerNum. after this I would like to use that number extracted in a url for example:
http://seriallookup.com/serial=SerNum
推荐答案
以下作品! / p>
The following works!
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("szCPUSer.dat", ForReading)
For i = 1 to 10
objTextFile.ReadLine
Next
strLine = objTextFile.ReadLine
Wscript.Echo strLine
objTextFile.Close
'Gets 6 chars starting from Right side
SerNum = Right(strLine, 6)
'Gets 6 chars starting from Left side
SerNum = Left(SerNum, 5)
'Wscript.Echo SerNum
url = "http://seriallookup.com/serial=" & SerNum
Wscript.Echo url
这篇关于VBScript读取特定行并提取字符并将其存储为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!