Q:

Write a C# Sharp program to remove the first and last elements from a given string

0

Write a C# Sharp program to remove the first and last elements from a given string

Sample Output:

Original string: PHP
After removing first and last elements: H
Original string: Python
After removing first and last elements: ytho
Original string: JavaScript
After removing first and last elements: avaScrip

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Original string: PHP");
            Console.WriteLine("After removing first and last elements: "+test("PHP"));
            Console.WriteLine("Original string: Python");
            Console.WriteLine("After removing first and last elements: " + test("Python"));
            Console.WriteLine("Original string: JavaScript");
            Console.WriteLine("After removing first and last elements: " + test("JavaScript"));
        }
        public static string test(string str1)
        {
            return str1.Length > 2 ? str1.Substring(1, str1.Length - 2) : str1;
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now