473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

VB searching in text file

AL
Hi
I have a bunch of text files which need to be organized.
What I want to do is to select three continuous lines from
each text file and write them down in another text file.
Each of those three line is started with character such
as "IH".
There are also more lines repeated after these three lines
which are started with the same character, but I do not
want to take them.

Thanks
Al
Nov 20 '05 #1
17 8483
Open the file and use the split method to split the file contents at the
return lines (split(mycontents, vbcrlf)). Now check the first member of the
array to make sure it starts with "IH" and take the next two members of the
array. Now write this to a new textstream.

Is this what your after?
sp**@ahwayside.com

"AL" <ar*@coe.neu.edu> wrote in message
news:13****************************@phx.gbl...
Hi
I have a bunch of text files which need to be organized.
What I want to do is to select three continuous lines from
each text file and write them down in another text file.
Each of those three line is started with character such
as "IH".
There are also more lines repeated after these three lines
which are started with the same character, but I do not
want to take them.

Thanks
Al

Nov 20 '05 #2
Hello,

"AL" <ar*@coe.neu.edu> schrieb:
I have a bunch of text files which need to be organized.
What I want to do is to select three continuous lines from
each text file and write them down in another text file.
Each of those three line is started with character such
as "IH".
There are also more lines repeated after these three lines
which are started with the same character, but I do not
want to take them.


You already got an answer to your question. Please always stay in the
original thread. Feel free to reply further questions to your previous
thread.

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3
Al
Hi
How should I use the split function.
Should I just write: Character = lines(Split("IH",
vbCrLf))
I did not find any help in MSDN.
I appreciate if you explain it in detail.
Thanks
-----Original Message-----
Open the file and use the split method to split the file contents at thereturn lines (split(mycontents, vbcrlf)). Now check the first member of thearray to make sure it starts with "IH" and take the next two members of thearray. Now write this to a new textstream.

Is this what your after?
sp**@ahwayside.com

"AL" <ar*@coe.neu.edu> wrote in message
news:13****************************@phx.gbl...
Hi
I have a bunch of text files which need to be organized. What I want to do is to select three continuous lines from each text file and write them down in another text file. Each of those three line is started with character such
as "IH".
There are also more lines repeated after these three lines which are started with the same character, but I do not
want to take them.

Thanks
Al

.

Nov 20 '05 #4
Hi Al,

In answer to your previous query, Herfried said:

|| Have a look at the classes 'StreamReader' and
|| 'StreamWriter' in the 'System.IO' namespace.
|| You can use the 'StreamReader''s 'ReadLine'
|| method to read a line from the file.

Did you look at them? If not, why not?
Did you thank him? If not, why not?

Method:

Open a StreamWriter for the output file.
For each input file
Open a StreamReader for the input file
Read each line.
If it starts with "IH" then Bingo.
Write the line to the StreamWriter
Read and write the next two lines.
Close the StreamReader
Next
Close the StreamWriter

Regards,
Fergus
Nov 20 '05 #5
Basic code for reading the lines of a file:

\\\
Imports System.IO
..
..
..
Dim sr As New StreamReader("C:\WINDOWS\WIN.INI")
Dim strLine As String
strLine = sr.ReadLine()
Do Until strLine Is Nothing
MsgBox(strLine)
strLine = sr.ReadLine()
Loop
sr.Close()
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #6
Hello,

"Al" <ar*@coe.neu.edu> schrieb:
How should I use the split function.
Should I just write: Character = lines(Split("IH",
vbCrLf))
I did not find any help in MSDN.
I appreciate if you explain it in detail.


\\\
Dim s As String = "Hello" & ControlChars.NewLine & "Bla"
Dim astr() As String = Split(s, ControlChars.NewLine)
Dim x As String
For Each x In astr
MsgBox(x)
Next x
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #7
Al
Hi Fergus,
I did not find those in MSDN help? Are those VB classes?
Let me know where I can find them.
I am going to email Herfried.
Thanks
Ali
-----Original Message-----
Hi Al,

In answer to your previous query, Herfried said:

|| Have a look at the classes 'StreamReader' and
|| 'StreamWriter' in the 'System.IO' namespace.
|| You can use the 'StreamReader''s 'ReadLine'
|| method to read a line from the file.

Did you look at them? If not, why not?
Did you thank him? If not, why not?

Method:

Open a StreamWriter for the output file.
For each input file
Open a StreamReader for the input file
Read each line.
If it starts with "IH" then Bingo.
Write the line to the StreamWriter
Read and write the next two lines.
Close the StreamReader
Next
Close the StreamWriter

Regards,
Fergus
.

Nov 20 '05 #8
Al
Hi
I am going to use what you wrote and see what will happen.
Bye the way, regarding to the previous answer you gave me,
I did not find those classes in VB.
Thanks
Al
-----Original Message-----
Hello,

"Al" <ar*@coe.neu.edu> schrieb:
How should I use the split function.
Should I just write: Character = lines(Split("IH",
vbCrLf))
I did not find any help in MSDN.
I appreciate if you explain it in detail.


\\\
Dim s As String = "Hello" & ControlChars.NewLine & "Bla"
Dim astr() As String = Split(s, ControlChars.NewLine)
Dim x As String
For Each x In astr
MsgBox(x)
Next x
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
.

Nov 20 '05 #9
Al
Hi
Bye the way, how should I pick up a line from the file? I
am nearly good in VB, but I still do not know some easy
stuff. sorry
here is what I have.
dim temp as string '( it has been already defined to pick
up a file with a path)
open temp for input as #filenum
?? what shoud I write to get the line in a line character
Once I get the line character I do what you said in
previous reply.

Thanks
Al
-----Original Message-----
Hello,

"Al" <ar*@coe.neu.edu> schrieb:
How should I use the split function.
Should I just write: Character = lines(Split("IH",
vbCrLf))
I did not find any help in MSDN.
I appreciate if you explain it in detail.


\\\
Dim s As String = "Hello" & ControlChars.NewLine & "Bla"
Dim astr() As String = Split(s, ControlChars.NewLine)
Dim x As String
For Each x In astr
MsgBox(x)
Next x
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
.

Nov 20 '05 #10
"Al" <ar*@coe.neu.edu> schrieb
open temp for input as #filenum


Your code is VB6 (or earlier) code. This is a VB.NET language group (see
group name). For older version please turn to one of the
microsoft.public.vb.* groups.
--
Armin
Nov 20 '05 #11
"Al" <ar*@coe.neu.edu> schrieb
I am going to use what you wrote and see what will happen.
Bye the way, regarding to the previous answer you gave me,
I did not find those classes in VB.


Are you sure, you are talking about VB.NET?
--
Armin

Nov 20 '05 #12
Hi Al,

I have to wonder - are you doing this in VB6 (or earlier) or in VB.NET?
Because StreamReader and StreamWriter are fundamental classes in the .NET
framework.

Herfried gave you a complete example this morning (post timed 11:41am)
which showed you how to use the StreamReader.

However, I accept that if you're still thinking in terms of Open For Input
As #FileNum then this would not mean so much to you.

It's time to say goodbye to Open For... and say hello to Streams.

I've given the complete solution in general terms in my post. Herfried has
given you the details of the reading in his post. The writing is very similar
to the reading.

With what we've given you plus reading and trying out the following, you
should be able to do what you want.

http://support.microsoft.com/default...en-us;315828#2

Come back with any more queries, but please, it would be nice if you could
show that you've studied what we've given you. :-)

All the best,
Fergus
Nov 20 '05 #13
"Al" <ar*@coe.neu.edu> schrieb:
I am going to use what you wrote and see what will happen.
Bye the way, regarding to the previous answer you gave me,
I did not find those classes in VB.


Do you use VB.NET or VB Classic?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #14
"Al" <ar*@coe.neu.edu> schrieb:
I did not find those in MSDN help? Are those VB
classes?
Those are .NET classes (classes included in the .NET Framework).
Let me know where I can find them.
I am going to email Herfried.


Please don't write private mail, always stay in the ngs. Thanks!

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #15
"Al" <ar*@coe.neu.edu> schrieb:
Bye the way, how should I pick up a line from the file? I
am nearly good in VB, but I still do not know some easy
stuff. sorry
here is what I have.


If you use VB Classic (VB6), please turn to one of the microsoft.public.vb.*
ngs. Have a look at the documentation for 'Open', 'Close' and 'Line Input'.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #16
"Ali" <ar*@coe.neu.edu> schrieb:
I have VB6. sorry I forgot to mention, because I just
heard about vb.net.
Can I use stream in vb6?


No.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #17
"Ali" <ar*@coe.neu.edu> schrieb
Hi
I have VB6. sorry I forgot to mention, because I just
heard about vb.net.
Can I use stream in vb6?


Yes, add a Class file and call it "Stream". Then you've got a Stream class.
Unfortunatelly it doesn't do anything. Hmm...you'd better not use a Stream
in VB6.

SCNR ;-)
--
Armin

Nov 20 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: hivie | last post by:
I have a problem that is causing me problems. I have a text file that stores 5 lines of crap (stuff that I dont need( for the user only)). After that there is data that is in three columns...
7
by: Santah | last post by:
hi I'm new to C++ and I'm currently working on Visual C++ 6.0 I'm trying to open a text file, and read some data from it part of the text file looks like this: --------
4
by: Michi | last post by:
I was wondering what the best solution is for making large numbers of TEXT (or BLOB?) fields searchable. For example, if I have a forum, what is the best way to be able to search for specific...
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
10
by: mjl1976 | last post by:
I have textBox1 which is the string i want to search in file.txt Button1 I want textBox2 to show the line of text i am searching when i click button1
4
by: dexter48 | last post by:
Hi I'm searching for a string occurance in a text file. I find the string ok and write the results to a log file. But on the line above is also some information I need. How can i get that. The string...
6
by: d4 | last post by:
I added a Text file to my Project (Add New Item Text File). I've added a button so when a user clicks on it it will bring up the text file to read, only problem is I cannot figure out how to call...
2
by: jld730 | last post by:
Greetings! I am still new to Python, sorry! I have been searching through many posts on this subject and have attempted to TRY, but I feel really lost. So, any detailed guidance would be oh-so...
3
by: itdaddy | last post by:
hey perl gurus! i am new to this forum cause i need help. I have done many scripts. but i want to use perl to do this: What I want to do is this. I have a QRP file that I can convert to a txt...
1
by: rajnish singh | last post by:
I have to search x,y cordinates from a text file.Ater searchig x,y value from the file ,the value of x,y should change in other format in output mode. Suppose we have x=33.5,y=77.5 in output...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.