473,414 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to append string to string builder in C#

Hi,

I have used stream reader to read text file using Readline method, and i tried to append all string to string builder, but i'm not able to get all string value, i'm only getting last line of file, i have used the following coding

StreamReader reader = new StreamReader(@"d:\web_extract.txt",Encoding.Defaul t);
StringBuilder strbuild = null;
StreamWriter writer = null;
while(reader.Peek() >= 0)
{
string str = null;
str = reader.ReadLine().ToString();
str = str.Replace("Ú"," ");
strbuild = new StringBuilder();
// str = strbuild.Replace("Ú"," ").ToString();
strbuild.Append(str);

}
string str1 = strbuild.ToString();
reader.Close();
writer = new StreamWriter(@"d:\web_extract1.txt",true);
writer.Write(str1);
writer.Close();

Please anybody help to solve this problem, advanced thanks for any reply.

Thanks.
Mar 17 '07 #1
2 1642
Hi,

I think you have to put the following line outside the while loop.

strbuild = new StringBuilder();


Regards
Mohith


Hi,

I have used stream reader to read text file using Readline method, and i tried to append all string to string builder, but i'm not able to get all string value, i'm only getting last line of file, i have used the following coding

StreamReader reader = new StreamReader(@"d:\web_extract.txt",Encoding.Defaul t);
StringBuilder strbuild = null;
StreamWriter writer = null;
while(reader.Peek() >= 0)
{
string str = null;
str = reader.ReadLine().ToString();
str = str.Replace("Ú"," ");
strbuild = new StringBuilder();
// str = strbuild.Replace("Ú"," ").ToString();
strbuild.Append(str);

}
string str1 = strbuild.ToString();
reader.Close();
writer = new StreamWriter(@"d:\web_extract1.txt",true);
writer.Write(str1);
writer.Close();

Please anybody help to solve this problem, advanced thanks for any reply.

Thanks.
Mar 17 '07 #2
kenobewan
4,871 Expert 4TB
For every line your string is being reset to null except the last line where it exits the loop. HTH.
Mar 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: cody | last post by:
Why isn't there an StringBuilder.Append() overload with a StringBuilder as argument? Is there a reason that I missed?
1
by: PMB | last post by:
Thank you in advance for any and all assistance. I'm trying to use a make table query to pull the last transactionID, so I can use an append query to reset the transactionID to the next...
18
by: Marcio Kleemann | last post by:
I need to force the first letter of each word in a line of text to uppercase. The text comes from a TextBox control in a Web Form. I'm new to ..NET and am having a problem. Since I can't modify...
8
by: Two Beards | last post by:
Hi, I'm new to VB and .net so I may be mising something. I am trying to dynamically build some SQL by appending to a string. Part of the SQL comes from an mp3 id tag I have extracted from a file...
33
by: sklett | last post by:
I need to take a string, make the first character lowercase and prepend an underscore character to it. Something like this: "California" "_california" Here is the (ugly) solution I cam up...
9
by: Mosquito Man | last post by:
string s("0101"); I can't change it into s=1101 by s='1'; because string.this is read-only, no assignment is allowed :-( thank you for your help
5
by: TazaTek | last post by:
Hello, I've seen some vague references on how to do this a factory, but not in enough detail to create one, or even know if it's what I need. Essentially, I'll have one of about 5 classes that...
10
by: Lonifasiko | last post by:
Hi, Just want to replace character at index 1 of a string with another character. Just want to replace character at that position. I thought Replace method would be overloaded with an index...
7
by: wade.wall | last post by:
Hi all, I am having a problem appending data to an existing table. I have two tables with identical fields and I want to append the data from one table (T2) to the first (T1). T1 has 136...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.