A string in C# is an immutable sequence of UTF-16 characters. Immutable is the word that explains most of the surprises: every method that looks like it changes a string actually returns a new one, and the original is untouched. That is why Replace and Trim have return values, and why building a string in a loop is slow enough to need StringBuilder.

Strings are the biggest topic on this blog. Almost every program reads text, checks it, reshapes it or writes it out. The articles below are grouped by the job you are doing, so something that lives on Regex sits beside something that lives on string.

New to C#, start with the first section. Otherwise the headings should get you to the right article in one click.

String Basics and Formatting

How to build a string, put values inside it and control how it looks.

Bytes, Encoding and Memory

A string is characters to you and bytes to everything else. These articles cover the crossing, and how to do it without allocating.

Splitting, Joining and Rearranging

Cutting a string apart and putting it back together, which is most of the text work in a normal application.

Searching, Comparing and Checking

Asking a string a question: does it contain this, where is it, is it empty.

Converting Between Strings and Other Types

Text in, value out, and back again. Most of these have a fast way and a safe way, and the articles show both.

Regular Expressions, Parsing and Text Sources

When the text has structure, you stop using string methods and start using a parser.

More String Techniques

Everything else we have written about strings and text.

Where to Go Next

Where text usually goes next:

Most string work is fast enough that readability wins. Reach for StringBuilder, Span and StringPool once you have measured a problem.