When exactly should a StringBuilder be used?

This is a discussion on When exactly should a StringBuilder be used? within the C# Programming forums, part of the General Programming Boards category; Hi! I’m very interesting in when to use exactly the StringBuilder? For example for something like this?: String strTest1 = ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    101

    When exactly should a StringBuilder be used?

    Hi!

    I’m very interesting in when to use exactly the StringBuilder?

    For example for something like this?:

    String strTest1 = “This”;
    String strTest2 = “Test”;
    StringBuilder stbTest = new StringBuilder();
    stbTest.Append(strTest1). Append(“is a ”). Append(stbTest);


    can someone provide some sample codes when to use a StringBuilder?

    And can someone tell me his experience about the performance of a StringBuilder?


    Regards,


    gicio

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    System::String is optimized for static, non-changing strings. System::Text::StringBuilder is optimized for string operations like replacing, appending, deleting etc.

    If you are doing more with your string than just formatting it once, StringBuilder will be more efficient in speed and memory management.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading Process Memory
    By polydegmon in forum C# Programming
    Replies: 0
    Last Post: 05-26-2009, 07:18 AM
  2. C# call Delphi DLL Error.
    By sergioms in forum C# Programming
    Replies: 14
    Last Post: 12-03-2008, 08:09 AM
  3. StringBuilder
    By C of Green in forum C# Programming
    Replies: 1
    Last Post: 11-18-2006, 09:15 AM
  4. Having a problem with string, not sure where to look
    By CompiledMonkey in forum C++ Programming
    Replies: 30
    Last Post: 11-26-2005, 05:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21