C# StringBuilder Methods

Beginner
5 min read
Updated: Nov 2026
13 method guides
Method index

About This Index

This page is the C# StringBuilder Methods index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs. Every example uses small fixed text and numbers, and formats numbers and dates with CultureInfo.InvariantCulture where it matters, so the output you see is the output you get.

Learn why StringBuilder exists on the StringBuilder hub. Use this page when you need a specific API such as Append(), Insert(), or ToString(). For the read-only text type, see String Methods.

A string you can change.

A normal string never changes: every + makes a brand-new string. A StringBuilder keeps one growing buffer, so adding text in a loop is cheap. Most methods return the same builder, so calls can be chained. Call ToString() once at the end to get the finished string.

How to Call a StringBuilder Method

Every method here is an instance method, so you call it on your builder variable:

C#
using System.Text;

StringBuilder sb = new StringBuilder();
sb.Append("Hello");                    // Hello
sb.Append(' ').Append("World");        // Hello World (chained)
sb.Insert(0, ">> ");                   // >> Hello World
sb.Replace("World", "C#");             // >> Hello C#
int chars = sb.Length;                 // 11
string text = sb.ToString();           // the finished string

C# StringBuilder Methods Table

All method guides in this C# tutorial series (13 tutorials), grouped by purpose.

Add text at the end

4 methods

Grow the buffer: add any value, a formatted message, a joined list, or a whole line. Each call returns the same builder, so calls can be chained.

MethodDescriptionTutorial
Append()Add any value to the end of the builder and get the same builder back for chaining.Try it
AppendFormat()Add a composite-format message like "{0} is {1}" with values filled into the placeholders.Try it
AppendJoin()Add every item of a list or array to the builder with a separator between them.Try it
AppendLine()Add optional text followed by a line break (Environment.NewLine).Try it

Edit in place

4 methods

Change the text that is already in the buffer: put text in the middle, cut a range out, swap one value for another, or empty everything.

MethodDescriptionTutorial
Insert()Put text or a value at any position; the characters after it move to the right.Try it
Remove()Cut a range of characters out of the builder by start position and length.Try it
Replace()Swap every occurrence of a string or char for another one, in the whole text or a range.Try it
Clear()Remove all characters (Length becomes 0) so the builder can be reused; memory is kept.Try it

Read / copy out

3 methods

Turn the buffer into a normal string, copy some characters into an array or span, or walk the internal pieces without making a string.

MethodDescriptionTutorial
ToString()Turn the builder (or part of it) into a normal string you can print, store, or compare.Try it
CopyTo()Copy a range of characters from the builder into a char array or a span.Try it
GetChunks()Walk the builder's internal pieces of text as ReadOnlyMemory<char> chunks, without making one big string.Try it

Compare and capacity

2 methods

Check whether two builders hold the same text, and reserve room before a large build.

MethodDescriptionTutorial
Equals()Check whether two builders (or a builder and a span) hold the same characters.Try it
EnsureCapacity()Reserve room for at least a number of characters before a big build; returns the new capacity.Try it

Frequently Asked Questions

They are the methods on System.Text.StringBuilder, a mutable text buffer. They add text at the end, insert, remove, and replace text in place, empty the buffer, copy characters out, compare builders, reserve capacity, and turn the result into a string.
This index lists 13 guides: Append, AppendFormat, AppendJoin, AppendLine, Clear, CopyTo, EnsureCapacity, Equals, GetChunks, Insert, Remove, Replace, and ToString.
Append, AppendFormat, AppendJoin, AppendLine, Insert, Remove, Replace, and Clear all return the same StringBuilder, so you can write sb.Append("a").Insert(0, "b").Replace("a", "c"). CopyTo returns nothing, and ToString, Equals, EnsureCapacity, and GetChunks return other types.
Length is the number of characters the builder holds right now. Capacity is how many characters fit before the builder needs more memory. Capacity is always at least Length and grows on its own.
Read the C# StringBuilder hub first. Then open Append(), AppendLine(), Insert(), and ToString() from the tables below.

Start with Append()

Add your first pieces of text to a builder and see how one buffer grows instead of creating a new string each time.

Append() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful