简体   繁体   中英

Read specific text in txt file in VBScript

I have a txt file containing 5 lines. I want to read the 1st line and 5th line but I do not want to read the first word so here's an example of what the txt file contains:

Title:        [Abo Manten] Kyuusho seme maniacs vol. 3 (Weak Spot Maniacs vol.3)
Upload Time:  2012-08-29 15:20
Uploaded By:  Hairs Fan
Downloaded:   2012-09-17 12:11
Tags:         swimsuit, abo manten, femdom, cbt, footjob

So I want to read the 1st line but I don't want to read the word Title: Same thing goes for the 5th line I don't want to read the word Tags:

So far my code just reads 1st line and 5th line. The 5th line also splits the text by comma. I don't know how to make 1st & 5th line to not read the specific words.

Set f = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\PATH\TO\your.txt", 1)
line1 = f.ReadLine
f.SkipLine
f.SkipLine
f.SkipLine
line5 = Split(f.ReadLine, ",")
f.Close
Set f = CreateObject("Scripting.FileSystemObject").OpenTextFile("test.txt", 1)
line1 = replace(f.ReadLine,"Title:","")
f.SkipLine
f.SkipLine
f.SkipLine
line5 = Split(replace(f.ReadLine,"Tags:",""), ",")
f.Close

This will replace Title & Tags from perticular Line.

Cheers! Amit C.

Another option would be to split the lines at the first colon:

Set f = CreateObject("Scripting.FileSystemObject").OpenTextFile("test.txt", 1)
line1 = Trim(Split(f.ReadLine, ":", 2)(1))
f.SkipLine
f.SkipLine
f.SkipLine
line5 = Split(Trim(Split(f.ReadLine, ":", 2)(1)), ", ")
f.Close

'use the Replace value tool. its easy. let say you have a value fline which = "i am a big man".

'if you run the following code:

fline = Replace(fline, "big ", "")

'here is the result value of fline:

msgbox fline 'which is "i am a man"

'cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM