?
Solved

Stringbuilder not working

Posted on 2006-10-23
1
Medium Priority
?
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 13

Accepted Solution

by:
devsolns earned 1400 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 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