Q:

Write a C# Sharp program to create a new string from a given string. If the two characters of the given string from its beginning and end are same return the given string without the first two characters otherwise return the original string

0

Write a C# Sharp program to create a new string from a given string. If the two characters of the given string from its beginning and end are same return  the given string without the first two characters otherwise return the original string

Sample Output:

cab
Python

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(test("abcab"));
            Console.WriteLine(test("Python"));
           
            Console.ReadLine();
        }

    public static string test(string s1)
          {
            if (s1.Length > 1 && s1.Substring(0, 2) == s1.Substring(s1.Length - 2))
            {
                return s1.Substring(2);
            }
            else
            {
                return s1;
            }
        }
   }
}

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