| | |
Please anybody to help to read string value in text file using C#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2006
Posts: 12
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Dec 2006
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
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.
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:
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:
C# Syntax (Toggle Plain Text)
System.IO.StreamReader StreamReader1 = new System.IO.StreamReader("myfile.txt"); String data = StreamReader1.ReadToEnd(); textBox.Text = data; StreamReader1.Close();
Sir David Healy - Northern Ireland Goal King
•
•
Join Date: Dec 2006
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
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:
C# Syntax (Toggle Plain Text)
System.IO.StreamReader StreamReader1 = new System.IO.StreamReader("myfile.txt"); String data = StreamReader1.ReadToEnd(); textBox.Text = data; 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.
![]() |
Similar Threads
- Cant readline in text file.... URGENT help~ (VB.NET)
- Trying to obtain text from a file. (C#)
- using a "for" loop to read a text file (VB.NET)
- Read in a string from a text file (C)
- write to text file using fprintf() (C)
- string: get token from string and compare token from text file (C++)
- New User (C)
- Read and write to an ASCII Text file (Java)
Other Threads in the C# Forum
- Previous Thread: a very simple csv reader question
- Next Thread: Arranging Windows Forms
| Thread Tools | Search this Thread |
.net access algorithm animation array barchart bitmap box broadcast c# check checkbox client code combobox control conversion csharp custom database datagrid datagridview dataset datastructure datetime degrees development directrobot display draganddrop drawing encryption enum excel file form format formbox forms function gdi+ hash image index input install java label list listbox mandelbrot math mouseclick mp3 mysql native networking operator packaging path photoshop picturebox pixelinversion post print process programming radians regex remoting richtextbox safari server sleep snooze socket sql statistics stream string table tables tcp text textbox thread time timer treeview update usercontrol usercontrols validation visualstudio webbrowser wfa windows winforms wpf xml





