C# String Methods

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 15 Tutorials
Reference Index

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.

01

Full Tutorials

15 methods with examples.

02

Quick Reference

All methods by category.

03

Searchable

Filter by method name.

04

Immutable Strings

Methods return new text.

05

Beginner Tips

Compare vs Equals explained.

06

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.

💡
Beginner Tip

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 methods

Duplicate 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 methods

Compare strings for equality, culture rules, ordinal order, and sortable IComparable results.

Search & Match

2 methods

Check whether text includes a substring or ends with a suffix—common for validation, URLs, and file extensions.

Build & Format

2 methods

Join multiple strings and build formatted messages with placeholders—both are static helpers on String.

Enumeration & Metadata

4 methods

Iterate 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; use Compare() with culture for user-visible sort order.
  • Null-safe checks — calling instance methods on null throws NullReferenceException. Guard with string.IsNullOrEmpty(text) first.
  • Choose the right searchContains() for presence, EndsWith() for suffixes like file extensions.
  • Prefer StringBuilder in loops — repeated + or Concat() in tight loops allocates many strings; build with StringBuilder instead.
  • Static vs instanceCompare(), Concat(), Format(), and Copy() 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

GoalExample
Check substringurl.Contains("/c-sharp")
Compare contentinput.Equals("yes", StringComparison.OrdinalIgnoreCase)
Sort two stringsString.Compare(a, b, StringComparison.Ordinal)
Check file extensionfile.EndsWith(".cs")
Format outputString.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

String methods are built-in operations on System.String for comparing text, searching substrings, joining strings, formatting output, copying characters, and reading metadata. You call most of them on a string variable: text.Contains("C#"), name.Equals("Admin"). Static methods use the class name: String.Format("Hi, {0}", name).
Use dot notation on a string instance: str.Length, str.Contains("test"), str.EndsWith(".cs"). Static methods use String or string: String.Compare(a, b), String.Concat(parts), String.Format("{0:N2}", price).
For strings, == compares character content (value equality), just like Equals(). The difference matters for other types; for String, both check whether the text matches. Use String.Equals(a, b, StringComparison.OrdinalIgnoreCase) when you need explicit comparison rules.
Compare() is static and culture-aware by default—good for user-facing sort order. CompareOrdinal() is static and uses raw Unicode code-point order—fast and consistent for identifiers and paths. CompareTo() is an instance method (IComparable) that compares this string to another with culture-sensitive rules.
No. String objects cannot change after creation. Methods like Concat() and Format() return new strings. For frequent edits in loops, use StringBuilder instead of repeated concatenation.
Start with Contains() and EndsWith() for everyday search checks, then Equals() for safe comparison, and Format() for readable output. Those four cover validation, equality, and display—the most common tasks in console apps and APIs.
Did you know?

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.

Contains() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

18 people found this page helpful