VBScript 读取特定行并提取字符并将其存储为变量 [英] VBScript to read specific line and extract characters and store it as a variable

查看:18
本文介绍了VBScript 读取特定行并提取字符并将其存储为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 VB 脚本,可以从文本文件中读取第 11 行.但是,我需要从该行中提取第 48 到 53 个字符并将其保存为变量.完成此操作后,我想使用该变量并在 web url 中使用它.下面的例子:

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 行

The script I have reads the 10th line

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

推荐答案

以下有效!

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆