C# String Methods
What You’ll Find Here
The System.String class provides methods for comparing text, searching substrings, joining strings, formatting output, copying characters, and reading runtime metadata. This page is your central hub: browse every method in our tutorial series, jump to full guides with examples and output, and learn patterns that work in real C# programs.
Full Tutorials
15 methods with examples.
Quick Reference
All methods by category.
Searchable
Filter by method name.
Immutable Strings
Methods return new text.
Beginner Tips
Compare vs Equals explained.
Start Here
Contains() → Format().
Introduction
In C#, strings are instances of System.String (alias string). You call methods with dot notation: text.Contains("C#"), name.Equals("Admin"), file.EndsWith(".cs"). Several helpers are static and live on the class: String.Compare(...), String.Concat(...), and String.Format(...).
Strings are immutable—once created, their characters cannot change. Methods like Concat() and Format() return new string objects rather than modifying the original.
For strings, == and Equals() both compare character content. When you need case-insensitive or culture-specific rules, pass a StringComparison value: text.Equals("hello", StringComparison.OrdinalIgnoreCase).
String Methods Index
Search by method name or browse by category. Cards marked Tutorial link to full guides with syntax, five examples, output, and FAQs.
Clone & Copy
3 methodsDuplicate string content or copy characters into a char array—understand when Clone() returns the same instance and when Copy() allocates new text.
Comparison & Ordering
4 methodsCompare strings for equality, culture rules, ordinal order, and sortable IComparable results.
Search & Match
2 methodsCheck whether text includes a substring or ends with a suffix—common for validation, URLs, and file extensions.
Build & Format
2 methodsJoin multiple strings and build formatted messages with placeholders—both are static helpers on String.
Enumeration & Metadata
4 methodsIterate characters, compute hash codes, and inspect runtime type information inherited from Object.
🚀 Usage Tips
- Pick the right compare — use
CompareOrdinal()for file paths and identifiers; useCompare()with culture for user-visible sort order. - Null-safe checks — calling instance methods on
nullthrowsNullReferenceException. Guard withstring.IsNullOrEmpty(text)first. - Choose the right search —
Contains()for presence,EndsWith()for suffixes like file extensions. - Prefer StringBuilder in loops — repeated
+orConcat()in tight loops allocates many strings; build withStringBuilderinstead. - Static vs instance —
Compare(),Concat(),Format(), andCopy()are static; most other methods run on a string variable. - Read the tutorial — each linked method page includes syntax, five examples, a quick reference table, and FAQs.
📝 How to Call a String Method
Instance methods run on a string variable; static methods use the String class name:
stringReference.MethodName(arguments) // instance
String.StaticMethod(arguments) // static Common Patterns
| Goal | Example |
|---|---|
| Check substring | url.Contains("/c-sharp") |
| Compare content | input.Equals("yes", StringComparison.OrdinalIgnoreCase) |
| Sort two strings | String.Compare(a, b, StringComparison.Ordinal) |
| Check file extension | file.EndsWith(".cs") |
| Format output | String.Format("Total: {0:C}", price) |
Instance Methods vs Static Methods
Most String methods run on an existing string object. Static methods belong to the String class and do not require a particular string instance to start with.
string greeting = "Hello";
bool found = greeting.Contains("ell"); // instance: search
bool match = greeting.Equals("Hello"); // instance: compare
string joined = String.Concat(greeting, ", C#!"); // static: join
string formatted = String.Format("Count: {0}", 42); // static: template
string copy = String.Copy(greeting); // static: duplicate Conclusion
C# String methods cover the text tasks you will use most as a beginner—from validating input and comparing passwords to formatting reports and copying characters into arrays. Use this index to find the right method quickly, then open the full tutorial for syntax, examples, and best practices.
Start with Contains() and Equals() if you are new to C# strings, then explore Format() and Compare() for output and ordering.
❓ Frequently Asked Questions
Tip: C# strings are immutable—methods like Concat() and Format() return a new string. Compare text with Equals() or == (both compare content for strings). Call static helpers on the class: String.Compare(...), String.Format(...), and String.Copy(...).
Start Your First String Method Tutorial
Open the Contains() guide—syntax, five examples, and a quick reference cheat sheet.
18 people found this page helpful
