- Interpolation:
$"Hello {name}"; format with{price:N2}. Length,ToUpper(),ToLower(),Trim()Contains(),IndexOf(),StartsWith()Substring(),Replace(),Split(),string.Join()- Verbatim strings
@"C:\path"ignore escape sequences.
C# Strings
Interpolation and string methods.
✍️ 2 exercises in this lessonKey Takeaways: C# Strings
Mastering C# Strings helps you write clean and reliable C# code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
C# Strings Code Example
C#string s = " Learn C# at CodesInTech ".Trim();
Console.WriteLine(s.Length);
Console.WriteLine(s.ToUpper());
Console.WriteLine(s.Substring(6, 2));
Console.WriteLine(s.Contains("Codes"));
Console.WriteLine(s.Replace("C#", ".NET"));
Console.WriteLine(string.Join("|", s.Split(' ')));
decimal fee = 25000m;
Console.WriteLine($"Fee: Rs {fee:N0}");
Console.WriteLine(@"C:\Users\Ali");
Output
23 LEARN C# AT CODESINTECH C# True Learn .NET at CodesInTech Learn|C#|at|CodesInTech Fee: Rs 25,000 C:\Users\Ali
Run this example on your own computer. The "Get Started" lesson shows how to set it up.
C# Strings Practice Exercises
Check what you learned in “C# Strings”.
/ 2 solved
Fill in the blank
Use string interpolation.
string msg = "Hello {name}";
✓ Correct!
Not quite. Try again.
Multiple choice
What is @"C:\Users" called?
✓ Correct!
Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services