C# String Examples
C# Basic
C# Data Type
C# OOP
C# IO
C# Graphics & UI
C# Advanced
To uppercase every first letter of a word in a string, you can use the TextInfo.ToTitleCase
method available in the System.Globalization
namespace. Here is an example:
using System.Globalization; string input = "the quick brown fox jumps over the lazy dog"; TextInfo ti = CultureInfo.CurrentCulture.TextInfo; string output = ti.ToTitleCase(input);
This will produce the following output: "The Quick Brown Fox Jumps Over The Lazy Dog".
To make the first letter of a string uppercase, you can use the String.ToUpper
method and then concatenate the rest of the string:
string input = "hello world"; string output = input.Substring(0, 1).ToUpper() + input.Substring(1);
This will produce the following output: "Hello world".
C# string to uppercase example:
string input = "Convert to uppercase"; string uppercase = input.ToUpper(); // Result: "CONVERT TO UPPERCASE"
Uppercase conversion in C# string:
Using the ToUpper
method to convert the entire string to uppercase.
string input = "Uppercase conversion"; string uppercase = input.ToUpper(); // Result: "UPPERCASE CONVERSION"
String.ToUpper method in C#:
string input = "String.ToUpper method"; string uppercase = input.ToUpper(); // Result: "STRING.TOUPPER METHOD"
C# convert string to uppercase without ToUpper:
string input = "Convert without ToUpper"; string uppercase = new string(input.Select(char.ToUpper).ToArray()); // Result: "CONVERT WITHOUT TOUPPER"
Case-insensitive uppercase conversion in C#:
string input = "Case-Insensitive Uppercase"; string uppercase = input.ToUpperInvariant(); // Result: "CASE-INSENSITIVE UPPERCASE"
C# uppercase first letter of each word in a string:
string input = "uppercase first letter"; string[] words = input.Split(' '); for (int i = 0; i < words.Length; i++) { words[i] = char.ToUpper(words[i][0]) + words[i].Substring(1); } string result = string.Join(' ', words); // Result: "Uppercase First Letter"
Uppercase specific characters in C# string:
string input = "Uppercase specific characters"; char[] specificChars = { 's', 'c' }; foreach (char c in specificChars) { input = input.Replace(c.ToString(), c.ToString().ToUpper()); } // Result: "UpperCaSe SpeCifiC CharaCterS"
C# uppercase only first letter of a string:
string input = "uppercase only first letter"; string result = char.ToUpper(input[0]) + input.Substring(1); // Result: "Uppercase only first letter"
Convert lowercase to uppercase in C#:
string input = "convert lowercase"; string uppercase = new string(input.Select(char.ToUpper).ToArray()); // Result: "CONVERT LOWERCASE"
Handling special characters during string uppercase conversion in C#:
string input = "Handling special characters"; string uppercase = new string(input.Select(c => char.IsLetter(c) ? char.ToUpper(c) : c).ToArray()); // Result: "HANDLING SPECIAL CHARACTERS"