473,385 Members | 1,798 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.

parse text file and export to xml file using C#

Hi there,

I have a text file that does not have any delimiters - it is simply assumed that I know how long each field is and they are always in the same order.
(i.e. JOHN DOE 12345606JUN072007JUL2009 34 PXP)

Using C# I need to:
1. Grab the information in the text file.
2. Parse it out by grabbing the different "fields" (5th to 9th char = name, 24th to 27th is product etc).
3. Sort the fields into the order I want (i.e. move the dates to the beginning, then the last name, then first name then product etc)
4. Export the result to an XML file.

Is there a Sample of C# code out there or a tutorial ANYWHERE that will show me how this is done? I'm at my wits end.
Thank you for any help!
Gwenna
Jun 29 '06 #1
3 18686
Tzumer
2
This is classic for the use of regex ( Regular Expressions )
do you need code samples for that?
Jul 6 '06 #2
this code works i did it for u, try it and tell me if u need more help

private void parse()
{
string sLine, sName, sProduct, sDate;

//initialize reader from ur existing text file ex. datafile.txt
// IF UR TEXT FILE IN NOT ON THE bin/debug use the full path
StreamReader sr = new StreamReader("datafile.txt");
//grab the first in a string
sLine = sr.ReadLine();

//cut the string into the parts u want as name, date,...
sName = sLine.Substring(5,3);
sDate = sLine.Substring(15,18);
sProduct = sLine.Substring(24,3);
sr.Close();

StreamWriter sw = new StreamWriter("outputfile.txt"); //enter the full path for the output file
//write the substrings u have now in an output file
sw.Write(sDate+" ");
sw.Write(sName+" ");
sw.Write(sProduct+" ");
sw.Close();
}
Jul 6 '06 #3
Don't forget to use
using System.IO;

regards,
Hesham el ebrashy
Jul 6 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: John M. Lembo | last post by:
I am using Perl to parse a text file and output to another file. The text file has data on Unix virtual memory (vmstat) and I want to delete lines that I don't want and output lines that I want to...
6
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to...
3
by: Roel Schoonveld | last post by:
In Access 97 I made an application that makes text files that are exported. The names of the files contain two variables: 1. the value of the field BRIN in a table VasteGegevens of my database....
2
by: Raghu Gupta | last post by:
Hi, Actually i am facing some problem using quickbooks and presently i am not so expert in using it. I am using c# code to retrive the data from quickbooks. it doesn't matter which language we...
5
by: Ash Phillips | last post by:
Ok, I'm not sure how I can explain this but here goes. I have this program that uses a ListView for entries. What I have the program doing is taking all the items from the listview, and writing...
3
by: hbarnett | last post by:
I am in process of converting Access 97 databases to Access 2003. Some of the Access 97 databases export data to a text file with a non standard file extension, such as "ext" or "NAL". When I try...
6
by: Vic4338 | last post by:
I have a database with 50000 records containing phone numbers, I need to export the phone numbers sorted by area code, and create/save to .txt using the area code as the phone number. I create...
0
by: sterrell | last post by:
I am reading text from a file and I need help on how to pass my array to my parse.. Sample text file is::: H 234 J 345 I 345 K 345 L 456 M 456
1
Colloid Snake
by: Colloid Snake | last post by:
Hey everyone. I'm currently attempting to band-aid an horrible use of a Cacti implementation (and I swear, this is only temporary! No, really! They told me it's in the budget for next year, and has...
0
by: dorothywtkhk | last post by:
Dear All, I got a problem with the following case: I would like to enable a button after the file export (using asp.net), the code is: Dim fi As System.IO.FileInfo = New...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.