Posts

Showing posts with the label C# Methods

String Methods in C#

String Methods in C# C# provides a rich set of methods to manipulate strings, making it easy to perform various operations like searching, replacing, formatting, and more. Here are some of the most commonly used string methods: Basic String Operations Length: Returns the number of characters in the string. C# string str = "Hello, World!"; int length = str.Length; // length = 13 ToUpper() and ToLower(): Converts the string to uppercase or lowercase. C# string str = "hello, world!"; string upper = str.ToUpper(); // upper = "HELLO, WORLD!" string lower = str.ToLower(); // lower = "hello, world!" Trim(): Removes leading and trailing whitespace. C# string str = " Hello, World! "; string trimmed = str.Trim(); // trimmed = "Hello, World!" Substring(): Extracts a substring from the string. C# string str = "Hello, World!"; string substring = str.Substring(7, 5); // substring = "World" Searching and Replacing In...