Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining Lines

Status
Not open for further replies.

stathread

Programmer
Jan 17, 2006
38
US
Is there a way to combine lines of a text file?

For example, id like to make this..
Bill Joeny
12 Deer Street
Orlando Fl, 32333
Josh Joeny
122 Deer Street
Orlando Fl, 32333

This..
Bill Joeny 12 Deer Street Orlando Fl, 32333
Josh Joeny 122 Deer Street Orlando Fl, 32333

Thanks.
 
Open your original file using a streamreader
Open a new temp file for writing using a streamwriter

Do a readline to read each line. If the line read is a zip code then write all of those lines into the new text file.

If you need to, delete the original file after closing it and rename the new temp file.

The combining of lines would be:

string text = "";

while (reader.EOF != false)
{
string temp = reader.Read();

if (temp is numeric) //find the appropriate call here
//Consider using a Regex (Regular Expression)
{
writer.WriteLine(text);
}
else
{
text += temp + " ";
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top