FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 21   



Following program shows you how to print character at given index in a given string.

using System;

class MainClass {
  public static void Main (string[] args) {
    Console.WriteLine("Please enter a string:");
    string input = Console.ReadLine();
    int length = input.Length;
      Console.WriteLine("Please enter an index between 0 to " + (length - 1));
      int index = Convert.ToInt32(Console.ReadLine());
      if (index < 0 || index >= length) {
        Console.WriteLine("Invalid input");
        } else {
          Console.WriteLine("Character at given position is: " + input[index]);
    }
  }
}

Output:

Please enter a string:
 jenni
Please enter an index between 0 to 4
 1
Character at given position is: e



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News