get first four characters of a string in csharp

To get the first four characters of a string in C#, you can use the Substring method. Here's an example:

main.cs
string input = "Hello World";
string firstFourCharacters = input.Substring(0, 4);
Console.WriteLine(firstFourCharacters); // Output: "Hell"
140 chars
4 lines

In the example above, the Substring method is used to extract the characters starting from index 0 (inclusive) to index 4 (exclusive) from the input string.

related categories

gistlibby LogSnag