Notification texts go here Contact Us Buy Now!

Getting the letters from one index to another in a string using C#

Getting the Letters from One Index to Another in a String Using C#

Getting the Letters from One Index to Another in a String Using C#

In C#, you can use the Substring method to get the letters from one index to another in a string. The Substring method takes two parameters: the starting index and the length of the substring.

Example

The following code shows how to use the Substring method to get the letters from index 3 to index 7 in the string "Hello World":

    string str = "Hello World";
    string substring = str.Substring(3, 5);

    Console.WriteLine(substring);
  

This code will print the following output:

    World
  

Additional Notes

  • The starting index is zero-based.
  • If the starting index is greater than or equal to the length of the string, an ArgumentOutOfRangeException is thrown.
  • If the length of the substring is greater than the number of characters remaining in the string, the substring will be truncated.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.