Ruriko
Ruriko

Reputation: 179

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

Upvotes: 0

Views: 8441

Answers (3)

mathew
mathew

Reputation: 1

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

Upvotes: 0

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200233

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

Upvotes: 1

Amyth
Amyth

Reputation: 66

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.

Upvotes: 2

Related Questions