Please anybody to help to read string value in text file using C#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2006
Posts: 12
Reputation: Rocksoft is an unknown quantity at this point 
Solved Threads: 0
Rocksoft Rocksoft is offline Offline
Newbie Poster

Please anybody to help to read string value in text file using C#

 
0
  #1
Mar 14th, 2007
Hi,


I have used C# in vs 2003, in my application i have to read text file, pick data from text file and insert into database, but the text file have some garbage value (garbage value "Ú" ) , so i should replcace this garbage value to single space, i tried to use stream reader to read text file, but the problem is stream reader not at all reading this garbage value, its awqlays neglecting this garbage value, the following code i have used in my application


StreamReader reader = new StreamReader(@"d:\web_extract.txt");
string str = reader.ReadToEnd();
StringBuilder strbuild = new StringBuilder(str);
string gb = "Ú";
reader.Close();
strbuild.Replace(gb," ");
StreamWriter writer = new StreamWriter(@"d:\web_extract.txt");
writer.Write(strbuild.ToString());
writer.Close();

please anybody help me to solve this problem and take me out, Advanced thanks for any reply.

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 173
Reputation: RwCC is an unknown quantity at this point 
Solved Threads: 4
RwCC's Avatar
RwCC RwCC is offline Offline
Junior Poster

Re: Please anybody to help to read string value in text file using C#

 
0
  #2
Mar 14th, 2007
Ok I am rather confused about what you want, so the Ú is not meant to be there but is added when you read?
Sir David Healy - Northern Ireland Goal King
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 12
Reputation: Rocksoft is an unknown quantity at this point 
Solved Threads: 0
Rocksoft Rocksoft is offline Offline
Newbie Poster

Re: Please anybody to help to read string value in text file using C#

 
0
  #3
Mar 14th, 2007
Originally Posted by RwCC View Post
Ok I am rather confused about what you want, so the Ú is not meant to be there but is added when you read?


Hi,

Thanks for your immedite reply, I want to rplace this string value( Ú ) to single space in my text file using C#, but problem is stream reader not reading this string value, could you please give some some way to read the text file in C#.


Thanks.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 173
Reputation: RwCC is an unknown quantity at this point 
Solved Threads: 4
RwCC's Avatar
RwCC RwCC is offline Offline
Junior Poster

Re: Please anybody to help to read string value in text file using C#

 
0
  #4
Mar 14th, 2007
Im still a little unsure of the problem (doing many things at once, not good!). Is it happening like this:

original file
Hello There

file contents from S/Reader
HelloÚThere

Is that how it is coming across? I used to get problems with Stream Reader This code (which is basically the same as yours) works fine without any strange additional characters:

  1. System.IO.StreamReader StreamReader1 =
  2. new System.IO.StreamReader("myfile.txt");
  3. String data = StreamReader1.ReadToEnd();
  4. textBox.Text = data;
  5. StreamReader1.Close();
Sir David Healy - Northern Ireland Goal King
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 12
Reputation: Rocksoft is an unknown quantity at this point 
Solved Threads: 0
Rocksoft Rocksoft is offline Offline
Newbie Poster

Re: Please anybody to help to read string value in text file using C#

 
0
  #5
Mar 14th, 2007
Originally Posted by RwCC View Post
Im still a little unsure of the problem (doing many things at once, not good!). Is it happening like this:

original file
Hello There

file contents from S/Reader
HelloÚThere

Is that how it is coming across? I used to get problems with Stream Reader This code (which is basically the same as yours) works fine without any strange additional characters:

  1. System.IO.StreamReader StreamReader1 =
  2. new System.IO.StreamReader("myfile.txt");
  3. String data = StreamReader1.ReadToEnd();
  4. textBox.Text = data;
  5. StreamReader1.Close();

Hi,

Thanks for reply, i have solved the problem, i have added the Encoding.Default to stream reader , now i'm able read the garbage value in my file,
StreamReader reader = new StreamReader(@"d:\web_extract.txt",Encoding.Default);

Thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC