Working with Strings
Manipulate and process text using C#'s powerful string handling features.
Working with Strings is a free C# Academy lesson on CoddyKit — lesson 5 of 5. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C# Academy learning path, one of 5 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Working with Strings
Welcome to the next lesson! In this lesson, you’ll learn how to use and manipulate strings in C#, one of the most versatile and essential data types in programming. Let’s get started!

2
What Are Strings?
A string is a sequence of characters, such as text, enclosed in double quotes. In C#, strings are objects of the System.String class and come with many built-in methods for manipulation.
Example: "Hello, World!" is a string.
Key Point: Strings are immutable, meaning their content cannot be changed after creation.
3
Declaring Strings
You can declare and initialize strings like this:
Tip: Use double quotes (") to enclose string values.
using System;
class Program {
static void Main() {
string greeting = "Hello, World!";
// Declare and initialize a string
Console.WriteLine(greeting);
// Outputs: Hello, World!
}
}
4
Concatenating Strings
You can combine two or more strings using the + operator or the String.Concat() method. Example:
Key Point: Concatenation is a common operation when working with strings.
using System;
class Program {
static void Main() {
string firstName = "John";
string lastName = "Doe";
string fullName = firstName + " " + lastName; // Concatenation using +
Console.WriteLine("Full Name: " + fullName);
string fullNameUsingConcat = String.Concat(firstName, " ", lastName); // Using String.Concat()
Console.WriteLine("Full Name (Concat): " + fullNameUsingConcat);
}
}
5
String Interpolation
String interpolation allows you to embed expressions directly into a string. Example:
Tip: Use the $ symbol before the string to enable interpolation.
using System;
class Program {
static void Main() {
string name = "Alice";
int age = 25;
string message = $"Hello, my name is {name} and I am {age} years old.";
Console.WriteLine(message);
// Outputs: Hello, my name is Alice and I am 25 years old.
}
}
6
Common String Methods
Strings in C# come with several built-in methods. Examples:
Key Point: Use these methods to manipulate strings efficiently.
using System;
class Program {
static void Main() {
string text = " C# Programming ";
Console.WriteLine("Original: '" + text + "'");
Console.WriteLine("Trimmed: '" + text.Trim() + "'");
// Removes leading and trailing spaces
Console.WriteLine("Uppercase: " + text.ToUpper());
// Converts to uppercase
Console.WriteLine("Lowercase: " + text.ToLower());
// Converts to lowercase
Console.WriteLine("Length: " + text.Length); // Gets the length of the string
}
}
7
Splitting and Joining Strings
You can split a string into an array of substrings or join an array into a single string. Example:
Tip: Use Split() and Join() for advanced string operations.
using System;
class Program {
static void Main() {
string sentence = "C# is fun to learn";
// Splitting
string[] words = sentence.Split(' '); // Splits the sentence by spaces
Console.WriteLine("Words:");
foreach (string word in words) {
Console.WriteLine(word);
}
// Joining
string joined = String.Join("-", words); // Joins words with a hyphen
Console.WriteLine("Joined: " + joined); // Outputs: C#-is-fun-to-learn
}
}
8
Practice Challenge
Write a program that takes a full name as input, splits it into first and last name, and displays them separately. Example:
using System;
class Program {
static void Main() {
Console.WriteLine("Enter your full name:");
string fullName = Console.ReadLine();
string[] names = fullName.Split(' ');
Console.WriteLine("First Name: " + names[0]);
if (names.Length > 1) {
Console.WriteLine("Last Name: " + names[1]);
} else {
Console.WriteLine("Last Name: Not provided");
}
}
}
9
10
Great Job!
Congratulations! You’ve learned how to declare, concatenate, manipulate, and split strings in C#. In the next lesson, we’ll explore control flow and conditional logic with switch statements. Let’s keep coding!

Frequently asked questions
Is the “Working with Strings” lesson free?
Yes — the full text of “Working with Strings” is free to read here on the web, and the C# Academy course includes 5 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C# Academy course, upgrade to CoddyKit PRO.
What will I learn in “Working with Strings”?
Manipulate and process text using C#'s powerful string handling features. You practise C# Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C# Academy?
No prior experience is required. C# Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 5 of 5, so you can start here or from the beginning and move at your own pace.
How long does the “Working with Strings” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C# Academy lesson?
Yes. Every C# Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.