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
424 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

691 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