C# String Methods: Contains, Split, Replace, Trim, Join, and More
C# strings are immutable, so every method that appears to modify a string actually returns a new one. The original is never changed.
This page covers the methods that appear in day-to-day C# code. For formatting numbers and dates inside strings, see the string.Format guide.
Quick answer: use
Containsto search,Splitto separate,Replaceto substitute,Trimto remove surrounding whitespace, andstring.Jointo combine multiple strings.
On this page
- Contains, StartsWith, EndsWith
- Split: Break a String into Parts
- Replace: Substitute Text
- Trim, TrimStart, TrimEnd
- ToUpper, ToLower
- Substring and IndexOf
- PadLeft and PadRight
- String.IsNullOrEmpty and IsNullOrWhiteSpace
- String.Join: Combine a Collection into a String
- String.Concat and + Operator
- Quick Reference
Contains, StartsWith, EndsWith
Split: Break a String into Parts
Replace: Substitute Text
Trim, TrimStart, TrimEnd
ToUpper, ToLower
Substring and IndexOf
PadLeft and PadRight
String.IsNullOrEmpty and IsNullOrWhiteSpace
String.Join: Combine a Collection into a String
String.Concat and + Operator
Quick Reference
| Method | What it does |
|---|---|
Contains(s) | Returns true if the string contains s |
StartsWith(s) | Returns true if string starts with s |
EndsWith(s) | Returns true if string ends with s |
IndexOf(s) | First index of s, or -1 if not found |
LastIndexOf(s) | Last index of s, or -1 if not found |
Replace(old, new) | Returns a new string with all occurrences replaced |
Split(char) | Splits into an array on the given delimiter |
Trim() | Removes leading and trailing whitespace |
TrimStart() | Removes leading whitespace |
TrimEnd() | Removes trailing whitespace |
ToUpper() | Converts all characters to uppercase |
ToLower() | Converts all characters to lowercase |
Substring(i, n) | Returns n characters starting at index i |
PadLeft(n) | Right-aligns in a field of width n |
PadRight(n) | Left-aligns in a field of width n |
IsNullOrEmpty(s) | true if null or "" |
IsNullOrWhiteSpace(s) | true if null, "", or whitespace only |
Take It Further

The community's favorite C# guide. Teaches every concept you just read about with clarity.
The C# Player's Guide: 5th Edition · RB Whitaker
Get it on Amazon →As an Amazon Associate I earn from qualifying purchases.
Related Articles
Use the $ prefix in C# to embed expressions in string literals. More readable than string.Format, and it supports format specifiers.
Use StringBuilder in C# for efficient string building in loops. Unlike immutable strings, it reuses the same buffer to avoid repeated memory allocations.
Learn C# string.Format specifiers for numbers, dates, currency, percentages, alignment, and zero-padding, compared with interpolation.
Learn how to use string.Join in C# to combine arrays, lists, and IEnumerable values with a separator, including commas, spaces, and custom delimiters.