473,498 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

text file read

I have to read a text file and parse it out to load to a db and I'm having
some issues in doing it. here is what the text file looks like
Dealership number: 98665362236
Location: Maryland
Owner: John Smith
Type: Luxury
BMW, 325i, VIN12363625252362, New,, 20051212. 35400, Ocoonner
Lexus, IS300, VIN6936363633363. Used, Small dent on driver side, 20050112,
24000, JSmith

I need to account the Dealership number
then get the other information starting with BMW, how can I skip line 2 thru
4 and still get teh dealership number and the lines starting with BMW?
so the file is
Make, Model, VIN#, New/Used, any details, date sold,. price and salesmen

Feb 13 '06 #1
2 1460
Well this might be a bit of a brute force method, but if this file is
line by line then couldn't you just read each line into a cell in an
array? Then you could just pick the cells you need to read into your
DB columns? I think that would be the easiest if the file is
segregated into lines like you describe.

HTH

V

Feb 13 '06 #2

When you load a textfile in C#, you get access to a ReadLine() method.

There's no rocket science here.
You need to ReadLine, and look for things you can bank on.
using System;
using System.IO;

class Test
{
public static void Main()
{
try
{ bool isANewCar = false; int lineRowPerSingleCar = 0;
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
lineRowPerSingleCar +=1; if
(line.Substring(0,10).ToUpper() == "DEALERSHIP"{ // figure out a way
to get the last characters, perhaps on the ":" isANewCar =
true;lineRowPerSingleCar = 0; //reset} switch
(lineRowPerSingleCar){ case 2: case 3: case 4: //do
nothing break; default: // do somehting else break;}
}
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}

It's ugly as sin, but that's how you read files, where the format is a
little whack.
Looking at it, I'd use "Dealership number" to signal a new car. And reset
the lineCounter based on that.
Ignore 2, 3, 4, and do something with the rest.

Perhaps the sample above can get you going.



"CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
I have to read a text file and parse it out to load to a db and I'm having
some issues in doing it. here is what the text file looks like
Dealership number: 98665362236
Location: Maryland
Owner: John Smith
Type: Luxury
BMW, 325i, VIN12363625252362, New,, 20051212. 35400, Ocoonner
Lexus, IS300, VIN6936363633363. Used, Small dent on driver side, 20050112,
24000, JSmith

I need to account the Dealership number
then get the other information starting with BMW, how can I skip line 2 thru 4 and still get teh dealership number and the lines starting with BMW?
so the file is
Make, Model, VIN#, New/Used, any details, date sold,. price and salesmen

Feb 13 '06 #3

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

Similar topics

22
61336
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
1
3581
by: wtnt | last post by:
Hello. I've searched all over and haven't seen another thread with this problem. Please bear with me as I try to explain. thanks. :) I have some programs that need to be cross-platform...
0
1728
by: Eric Lilja | last post by:
Hello, I have a text file that contains a number of entries describing a recipe. Each entry consists of a number of strings. Here's an example file with only one entry (recipe): Name=Maple Quill...
10
3622
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in...
4
12763
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
6
32842
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
6
2460
by: portCo | last post by:
Hello there, I am creating a vb application which is some like like a questionare. Application read a text file which contains many questions and display one question and the input is needed...
1
2301
by: Studlyami | last post by:
I have a text file which acts like an index to several other files. The text file contains <filename.txt>, <description for file name>. Every file listed in this index file contains data that i...
4
3375
by: Keith G Hicks | last post by:
I'm trying to read a text file and alter the contents of specific lines in the file. I know how to use streamreader to read each line of a file. I'm doing that already to get the data into a...
0
10705
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
7124
marktang
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,...
0
7200
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...
1
6884
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...
0
7375
tracyyun
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...
0
5460
agi2029
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,...
1
4904
isladogs
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...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
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...
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.