Solved

Vbscript: I want to read a string in a text file on a certain line delimited by a certain delimiter

Posted on 2011-03-14
5
382 Views
Last Modified: 2012-05-11
This string starts at the beginning of the line (I have the linenumber) and is delimited with the following delimiter : #.
0
Comment
Question by:itbabe
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:jawa29
ID: 35130037
This code will read eachline of a text file and pop up a window when it finds a line that has # at the start.

Will this give you a base to work on?

Jawa29
Const ForReading = 1

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile ("TextFileforReading.txt", ForReading)

Do Until oTextFile.AtEndOfStream
    sLine = oTextFile.ReadLine
    If Left(sLine, 1) = "#" Then
    	WScript.Echo sLine
    End If
Loop

Open in new window

0
 
LVL 8

Accepted Solution

by:
GundogTrainer earned 500 total points
ID: 35130240
Using the code posted by jawa29 I think this is what mean:
You have a text file,
you know that say line 10 is delimited with "#" and you want to examine that line.

Something like this should do that.
Const ForReading = 1
LineNumToRead=10 'you said you had the line number
CurrentLineNum=0
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile ("TextFileforReading.txt", ForReading)

Do Until oTextFile.AtEndOfStream
CurrentLineNum=CurrentLineNum+1
    sLine = oTextFile.ReadLine
    If CurrentLineNum=LineNumToRead then
         ArrLine=split(sLine,"#")
           For arrNum=0 to ubound(ArrLine) 'Loop through the line and display the individaul entries
             WScript.Echo arrNum,ArrLine(arrNum)
           Next
    End If
Loop

Open in new window

0
 

Author Comment

by:itbabe
ID: 35130267
Thanks for the help.
I need to be able to provide the line number at whic it should search for the string.
How can I achieve that ?
0
 
LVL 8

Expert Comment

by:GundogTrainer
ID: 35130297
Change LineNumToRead to the line number to inspect.
0
 
LVL 8

Expert Comment

by:jawa29
ID: 35130299
This one will read one line given by the paramater iLineNumber

Jawa29
Const FOR_READING = 1

iLineNumber = 5

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextFile = oFSO.OpenTextFile("TextFileForReading.txt", FOR_READING)

For i=1 To (iLineNumber-1)
   oTextFile.SkipLine
Next

WScript.Echo oTextFile.Readline

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now