Solved

Stringbuilder not working

Posted on 2006-10-23
1
359 Views
Last Modified: 2010-04-16
I'm trying to use a stringbuilder to add lines together if the line is shorter than 305 characters. It reads the first line fine, reads the nextLine fine and captures those.

For some reason when I get to the string myString part it's blank..  How do I get my results into myString? Thanks!

                            policyLine = line;
                            nextLine = sr.ReadLine();
                            if(nextLine.Length < 305)
                            {
                                StringBuilder sb2 = new StringBuilder();
                                sb2.Append(policyLine);
                                sb2.Append(@"\");
                                sb2.Append(nextLine);
                                string myString = sb2.ToString();                          
                            }
0
Comment
Question by:boukaka
1 Comment
 
LVL 13

Accepted Solution

by:
devsolns earned 350 total points
ID: 17790948
first you'll likely need to declare myString outside the if() scope if you want to use it outside that scope.  The use of StringBuilder looks fine.  Also for only 3 appends your gonna find that just concatenting strings is faster even though they are immutable.  I'd say almost 2x faster but you'll only notice the diff. in a lab.

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now