string myString = "Hello, World!"; string substr = myString.Substring(0, 5); // Extract the first five characters of the string Console.WriteLine(substr); // Prints "Hello"
string myString = "The quick brown fox jumps over the lazy dog."; string substr = myString.Substring(4); // Extract characters from index 4 to end of string Console.WriteLine(substr); // Prints "quick brown fox jumps over the lazy dog."In the second example, we create a string `myString` and then extract a substring starting from index 4 till the end of the string and print the result to the console. The `System.Substring` method is a part of the C# class library.