Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2006, 11:59 AM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Read all rows from text file

I need to read all the rows from text file , every time one row.
The text file is "tab delimited" (from excel) - so the space between the words is tab.

I need to take every time one row and split its words to array.

I hope U can help....

 
Old April 25th, 2006, 03:53 PM
Authorized User
 
Join Date: Apr 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Don't know if this is what you want... fileName is the file you want to read...

string s = String.Empty;
string[] words = new string[]{};
FileStream fs = new FileStream(fileName, FileMode.Open);
using(StreamReader sr = new StreamReader(fs))
{
    while(sr.Peek() > 0)
    {
        s = sr.ReadLine();
        words = s.Split('\t');
    }
}
fs.Close();

 
Old April 26th, 2006, 03:21 AM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!!!!!

I will check it and tell U if it work

 
Old April 26th, 2006, 10:14 AM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank but I used other way :

string file_name = @"C:\File1.txt";
StreamReader freader = File.OpenText( file_name );
char[] delimiterChars = {'\t' };
string text_line;
System.Data.DataRow myRow;
while (( text_line = freader.ReadLine() ) != null )
{
string[] words = text_line.Split(delimiterChars);

freader.Close();
}



 
Old April 26th, 2006, 10:20 AM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But still there is a problem :

When I try to read the content of the text and it is not number or english
(foreign language) it gives me " " (nothing).

Someone knows why?

 
Old April 28th, 2006, 09:37 PM
Authorized User
 
Join Date: Apr 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you resolved this? Probably your text is not well formed in foreign language...






Similar Threads
Thread Thread Starter Forum Replies Last Post
read text file senthilreddy ASP.NET 1.0 and 1.1 Basics 1 December 19th, 2010 10:56 PM
Read CSV file - Save Columns into Rows pintoo BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 1 August 20th, 2008 09:01 AM
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM
How to read a line from a text file ? nobitavn94 C# 3 November 25th, 2006 11:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.