C# String Methods

About This Index
This page is the C# String Methods index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn what a string is on /c-sharp/string. Use this page when you need a specific API such as Contains(), Equals(), or Format().
Start with Contains(), IndexOf(), Substring(), Split(), Replace(), and Trim(), then browse the rest by category. Every method that seems to “change” a string really returns a new one.
How to Call a String Method
Instance methods use a dot; static helpers use the class name:
string text = "Hello, C#!";
// Instance
bool hasCs = text.Contains("C#");
bool isCs = text.EndsWith("C#!");
bool same = text.Equals("Hello, C#!");
// Static
string joined = String.Concat("Hi", ", ", "C#");
string msg = String.Format("Count: {0}", 3); C# String Methods Table
All method guides in this C# tutorial series (50 tutorials).
Clone, copy & convert
6 methodsDuplicate a string, copy its characters into an array or span, or get the string back as itself.
| Method | Description | Tutorial |
|---|---|---|
Clone() | ICloneable; returns same string instance. | Try it |
Copy() | Static: new string with same chars. | Try it |
CopyTo() | Copy chars into a char array. | Try it |
TryCopyTo() | Copy into a Span<char> if it fits (bool). | Try it |
ToCharArray() | Copy chars into a new char[] you can edit. | Try it |
ToString() | Returns the same string instance. | Try it |
Build & format
5 methodsJoin pieces into one string, fill a template, insert text, or build a string directly in memory.
Comparison & ordering
4 methodsEquality, culture rules, ordinal order, and IComparable results.
| Method | Description | Tutorial |
|---|---|---|
Compare() | Static culture-aware comparison. | Try it |
CompareOrdinal() | Static ordinal (code-point) order. | Try it |
CompareTo() | Instance IComparable comparison. | Try it |
Equals() | Content equality check. | Try it |
Search & match
7 methodsCheck whether text starts with, ends with, or includes something, and find the position of a character or substring.
| Method | Description | Tutorial |
|---|---|---|
Contains() | Substring present anywhere? | Try it |
StartsWith() | Prefix match at the start. | Try it |
EndsWith() | Suffix match at the end. | Try it |
IndexOf() | First position of a char or substring (-1 if missing). | Try it |
IndexOfAny() | First position of any char from a set. | Try it |
LastIndexOf() | Last position of a char or substring (-1 if missing). | Try it |
LastIndexOfAny() | Last position of any char from a set. | Try it |
Cut, edit & split
7 methodsTake part of a string, remove or replace text, split it into pieces, or line it up with padding. Each call returns a new string.
| Method | Description | Tutorial |
|---|---|---|
Substring() | Copy part of a string by position and length. | Try it |
Remove() | Delete chars from a position (new string). | Try it |
Replace() | Swap every match for new text (new string). | Try it |
ReplaceLineEndings() | Make all line breaks the same (.NET 6+). | Try it |
Split() | Break into an array at separators. | Try it |
PadLeft() | Fill on the left to a width (right-align). | Try it |
PadRight() | Fill on the right to a width (left-align). | Try it |
Trim
3 methodsRemove spaces or chosen characters from the start, the end, or both ends.
Upper & lower case
6 methodsChange letter case with the current culture or with fixed invariant rules. The Ordinal pages explain what to use, because no such built-in method exists.
| Method | Description | Tutorial |
|---|---|---|
ToLower() | Lowercase copy (current culture). | Try it |
ToLowerInvariant() | Lowercase copy (invariant, same everywhere). | Try it |
ToLowerOrdinal() | Not a built-in method: use these instead. | Try it |
ToUpper() | Uppercase copy (current culture). | Try it |
ToUpperInvariant() | Uppercase copy (invariant, same everywhere). | Try it |
ToUpperOrdinal() | Not a built-in method: use these instead. | Try it |
Null & empty checks
2 methodsStatic tests that catch null, empty, and blank strings in one call.
| Method | Description | Tutorial |
|---|---|---|
IsNullOrEmpty() | Static: null or "" in one test. | Try it |
IsNullOrWhiteSpace() | Static: null, "", or only white space. | Try it |
Unicode & normalization
3 methodsWalk whole Unicode characters (runes) and make accented text compare the same way.
| Method | Description | Tutorial |
|---|---|---|
EnumerateRunes() | Loop over whole Unicode characters (runes). | Try it |
Normalize() | Put Unicode text into a standard form. | Try it |
IsNormalized() | Is the text already in a normal form? | Try it |
String pool (interning)
2 methodsShare one copy of repeated text through the runtime string pool.
| Method | Description | Tutorial |
|---|---|---|
Intern() | Static: get the pooled, shared copy. | Try it |
IsInterned() | Static: pooled copy or null (never adds). | Try it |
Enumeration & metadata
5 methodsIterate characters, compute hash codes, inspect runtime type information, and low-level pinning support.
| Method | Description | Tutorial |
|---|---|---|
GetEnumerator() | foreach over characters. | Try it |
GetHashCode() | Hash code for collections. | Try it |
GetType() | Runtime Type of instance. | Try it |
GetTypeCode() | TypeCode enum for the value. | Try it |
GetPinnableReference() | Low-level support for fixed (not for daily use). | Try it |
Frequently Asked Questions
Start with Contains()
Open the first search method guide—syntax, examples, and FAQs.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
15 people found this page helpful
