Sunday, July 22, 2007

String and StringBuilder

Difference: String & String Builder:
String object is immutable
A new string object is created whenever a string object is modified
System.Text.StringBuilder can be used for strings that are repeatedly modified
StringBuilder sb = new StringBuilder(), sb.Append(“text”);

StringBuilder Methods:
Append: Add to end of text
AppendFormat: Append with format specifications
AppendLine: Append with a linefeed
EnsureCapacity: Set the minimum size of StringBuilder
Remove: Removes specified range of characters
Replace: Replace one string from other

No comments: