Is there a way to read a specfic line in a text file? For instance if I
wanted to just read the 5th line is that possible without having to step
through the other lines? Essentially I am doing huge calculations in which
genetic matrices are saved in text files instead of being held in arrays that
take up memory. I am trying to do something where the genetic matrix is
stored in a text file and I call specfic lines for calculations then put the
results in another text file. Any help would be great,
Thanks, Adrian 6 1854
Hi Adrian,
I don't think there is a .Net way of doing that with file streams. What you
could do though to make it easier for you is create a helper function that
wraps the ReadLine function. You would pass this function the line you
want, your function would loop through and return the line you are looking
for. You are still looping but at least you would only have to write the
function once and you could call it from anywhere with 1 line of code.
An alternative is to create your text file so that all lines are the *exact*
same length. If you do this then you could just run a calculation as to
where in the file your data is. Then on the stream reader you can use the
BaseStream.Seek () function to go directly there. You'll probably need to
put in some filler characters, but filtering those out after you read the
line might be faster than looping. Good luck! Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try: http://www.webhost4life.com/default.asp?refid=Spinlight
"Adrian Lin" <Adrian Li*@discussions .microsoft.com> wrote in message
news:DA******** *************** ***********@mic rosoft.com... Is there a way to read a specfic line in a text file? For instance if I wanted to just read the 5th line is that possible without having to step through the other lines? Essentially I am doing huge calculations in which genetic matrices are saved in text files instead of being held in arrays
that take up memory. I am trying to do something where the genetic matrix is stored in a text file and I call specfic lines for calculations then put
the results in another text file. Any help would be great,
Thanks, Adrian
Hi Adrian,
I don't think there is a .Net way of doing that with file streams. What you
could do though to make it easier for you is create a helper function that
wraps the ReadLine function. You would pass this function the line you
want, your function would loop through and return the line you are looking
for. You are still looping but at least you would only have to write the
function once and you could call it from anywhere with 1 line of code.
An alternative is to create your text file so that all lines are the *exact*
same length. If you do this then you could just run a calculation as to
where in the file your data is. Then on the stream reader you can use the
BaseStream.Seek () function to go directly there. You'll probably need to
put in some filler characters, but filtering those out after you read the
line might be faster than looping. Good luck! Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try: http://www.webhost4life.com/default.asp?refid=Spinlight
"Adrian Lin" <Adrian Li*@discussions .microsoft.com> wrote in message
news:DA******** *************** ***********@mic rosoft.com... Is there a way to read a specfic line in a text file? For instance if I wanted to just read the 5th line is that possible without having to step through the other lines? Essentially I am doing huge calculations in which genetic matrices are saved in text files instead of being held in arrays
that take up memory. I am trying to do something where the genetic matrix is stored in a text file and I call specfic lines for calculations then put
the results in another text file. Any help would be great,
Thanks, Adrian
Adrian,
Do you know where the line starts in the file?
You could use Stream.Seek to position to that line, then you can read the
line.
Are the lines fixed length or variable length?
For fixed length lines, a simply calculation can find the offset to use.
For variable length lines, I would consider creating a second "index" file
that contains the offsets of each line as an Integer. A simply calculation
can find the offset to the index to use.
Post if you want examples.
Hope this helps
Jay
"Adrian Lin" <Adrian Li*@discussions .microsoft.com> wrote in message
news:DA******** *************** ***********@mic rosoft.com... Is there a way to read a specfic line in a text file? For instance if I wanted to just read the 5th line is that possible without having to step through the other lines? Essentially I am doing huge calculations in which genetic matrices are saved in text files instead of being held in arrays that take up memory. I am trying to do something where the genetic matrix is stored in a text file and I call specfic lines for calculations then put the results in another text file. Any help would be great,
Thanks, Adrian
Adrian,
Do you know where the line starts in the file?
You could use Stream.Seek to position to that line, then you can read the
line.
Are the lines fixed length or variable length?
For fixed length lines, a simply calculation can find the offset to use.
For variable length lines, I would consider creating a second "index" file
that contains the offsets of each line as an Integer. A simply calculation
can find the offset to the index to use.
Post if you want examples.
Hope this helps
Jay
"Adrian Lin" <Adrian Li*@discussions .microsoft.com> wrote in message
news:DA******** *************** ***********@mic rosoft.com... Is there a way to read a specfic line in a text file? For instance if I wanted to just read the 5th line is that possible without having to step through the other lines? Essentially I am doing huge calculations in which genetic matrices are saved in text files instead of being held in arrays that take up memory. I am trying to do something where the genetic matrix is stored in a text file and I call specfic lines for calculations then put the results in another text file. Any help would be great,
Thanks, Adrian
"Adrian Lin" <Adrian Li*@discussions .microsoft.com> wrote in message
news:DA******** *************** ***********@mic rosoft.com... Is there a way to read a specfic line in a text file? For instance if I wanted to just read the 5th line is that possible without having to step through the other lines? Essentially I am doing huge calculations in which genetic matrices are saved in text files instead of being held in arrays
that take up memory. I am trying to do something where the genetic matrix is stored in a text file and I call specfic lines for calculations then put
the results in another text file. Any help would be great,
Thanks, Adrian
I don't know if it would be any faster, but..
IF the files are small - you could do one read per file -
and read the entire contents into a String,
then use some string manipulation to extract the data.
reading loops are expensive - timewise - this may speed things up
Hal
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.768 / Virus Database: 515 - Release Date: 9/22/2004
Are there really so many that you cannot store them in memory until the end
of the run?
--
Jonathan Allen
"Adrian Lin" <Adrian Li*@discussions .microsoft.com> wrote in message
news:DA******** *************** ***********@mic rosoft.com... Is there a way to read a specfic line in a text file? For instance if I wanted to just read the 5th line is that possible without having to step through the other lines? Essentially I am doing huge calculations in which genetic matrices are saved in text files instead of being held in arrays
that take up memory. I am trying to do something where the genetic matrix is stored in a text file and I call specfic lines for calculations then put
the results in another text file. Any help would be great,
Thanks, Adrian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Suresh Kumaran |
last post by:
Hi All,
Does anybody know the sytax in VB.NET to write the
contents of a multiline text box to a text file?
Appreciate help.
Suresh
|
by: jamait |
last post by:
Hi all,
I m trying to read in a text file into a datatable...
Not sure on how to split up the information though, regex or substrings...?
sample:
Col1 Col2 Col3
Col4
A0012430 REKAL TVÄTTMEDEL EKOMAX 0,5L ST 75.9000
|
by: Roland Hall |
last post by:
I have two(2) issues.
I'm experiencing a little difficulty and having to resort to a work around.
I already found one bug, although stated the bug was only in ODBC, which I'm
not using. It appears to be in the OLEDB driver also.
My connection was:
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";" &
"Extended Properties='Text;HDR=NO;FMT=Delimited'"
|
by: googler |
last post by:
I'm trying to read from an input text file and print it out. I can do
this by reading each character, but I want to implement it in a more
efficient way. So I thought my program should read one line at a time
and print it out. How can I do this? I wrote the code below but it's
not correct since the fscanf reads one word (terminating in whitespace
or newline) at a time, instead of reading the whole line.
#include <stdio.h>
void...
|
by: Sabin Finateanu |
last post by:
Hi I'm having problem reading a file from my program and I think it's from a
procedure I'm using but I don't see where I'm going wrong. Here is the code:
public bool AllowUsage()
{
OperatingSystem os = Environment.OSVersion;
AppDomain ad = Thread.GetDomain();
| |
by: Adrian Lin |
last post by:
Is there a way to read a specfic line in a text file? For instance if I
wanted to just read the 5th line is that possible without having to step
through the other lines? Essentially I am doing huge calculations in which
genetic matrices are saved in text files instead of being held in arrays that
take up memory. I am trying to do something where the genetic matrix is
stored in a text file and I call specfic lines for calculations then put...
|
by: srikanthv |
last post by:
I have below Sample text. I need find in the text specfic "Key name"
its Value "HKEY_CURRENT_USER\Control Panel\International", If I find
this I need to go inside of this and read Value 0 (Name: Its value and
Data: Its value),Value 1 (Name: Its value and Data: Its value)....Value
N (Name: Its value and Data: Its value).
Please provide me same code for this.
Sample
-------
|
by: Stephen.Schoenberger |
last post by:
Hello,
My C is a bit rusty (.NET programmer normally but need to do this in
C) and I need to read in a text file that is setup as a table. The
general form of the file is
00000000 USNIST00Z 00000000_00 0 000 000 000 0000 000
I need to read the file line by line and eventually parse out each
piece of the file and store in arrays that correspond to the specific
|
by: xyz |
last post by:
Hi,
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..
ie., when i read for the first time , my program shuld read only one
line
and when i read for the next time , my program shuld read only second
line discarding first line..
i did it with ignore function but it is taking lot of time to reach
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |