VBScript to read specific line and extract characters and store it as a variable

本秂侑毒 提交于 2019-11-28 00:27:17

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

Take a look at InStr function. It lets you search for a substring.

http://www.w3schools.com/vbscript/func_instr.asp

Then you can use the Right function to parse out the end bit of the line.

You can also look at the Split function so you can parse the lines into arrays and deal with it that way which would be best.

http://www.w3schools.com/vbscript/func_split.asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!