Solved

Stringbuilder not working

Posted on 2006-10-23
1
363 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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