Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 25th, 2006, 11:59 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
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....

Reply With Quote
  #2 (permalink)  
Old April 25th, 2006, 03:53 PM
Authorized User
 
Join Date: Apr 2006
Location: , , .
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();

Reply With Quote
  #3 (permalink)  
Old April 26th, 2006, 03:21 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!!!!!

I will check it and tell U if it work

Reply With Quote
  #4 (permalink)  
Old April 26th, 2006, 10:14 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
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();
}



Reply With Quote
  #5 (permalink)  
Old April 26th, 2006, 10:20 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
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?

Reply With Quote
  #6 (permalink)  
Old April 28th, 2006, 09:37 PM
Authorized User
 
Join Date: Apr 2006
Location: , , .
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...

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.