Advertisement

07.10.2008 at 04:18AM PDT, ID: 23553298
[x]
Attachment Details

Why use StringBuilder, and how to search string in Stringbuilder object

Asked by mhouldridge in C# Programming Language

Tags: c#

Experts,

I've built a string using the StringBuilder as follows;

StringBuilder sb = new StringBuilder();

I then add items to sb  as follows:

 sb.AppendLine(str.ToString());

My questions are:

1. Why is a StringBuilder used, and not -  string += "Some more string";
2. How do I search in a string built using sb - My previous search are done on strings as follows:

int first = sb.IndexOf("silly");

...but the above doesnt work, because sb is a stringbuilder object, and not a string.  Should I just do..

string something = sb.ToString();
int first = sb.IndexOf("silly");

( Im worried the above could cause issues with larger strings).Start Free Trial
 
 
Loading Advertisement...
 
[+][-]07.10.2008 at 04:32AM PDT, ID: 21972207

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 04:38AM PDT, ID: 21972237

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C# Programming Language
Tags: c#
Sign Up Now!
Solution Provided By: jandromeda
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.10.2008 at 04:42AM PDT, ID: 21972253

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628