Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
444 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 2000 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 an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 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