Easily Truncating StringBuilder Strings

Just a quick one that I thought I’d pass along since it doesn’t seem to be common knowledge — it is documented on MSDN though.

Quick Tip

Do you need to remove characters from the end of a StringBuilder? Just decrement its Length property.

// Builder is a StringBuilder containing "Hello, world!1"
builder.Length--;
// Builder now contains "Hello, world!"

Couldn’t be easier.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s