1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

String Builder

Discussion in 'C#' started by rajrprk@gmail.com, Nov 14, 2011.

  1. rajrprk@gmail.com

    rajrprk@gmail.com New Member

    Joined:
    Nov 14, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    use of string builder in asp.net
    please post examples for string builder
     
  2. TradeM

    TradeM New Member

    Joined:
    Nov 27, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    StringBuilder sb = new StringBuilder("1 = ");
    sb.Append("One");
    sb.Append(Environment.NewLine);
    sb.AppendLine("2 = Two");
    sb.AppendLine("3 = Three");
    Displays:

    1 = One
    2 = Two
    3 = Three
     
  3. TradeM

    TradeM New Member

    Joined:
    Nov 27, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    StringBuilder can be used instead of String and it provides most of the methods of String class. Since strings are immutable (they cannot be changed) so even when you change a single character in string the whole string gets recreated. Therefore if you need to do many string manipulations you should use StringBuilder class instead for performance reasons.

    U Zafar
    Software Engineer
     
    Last edited by a moderator: Nov 28, 2011

Share This Page