Q:

Write a C# Sharp program to combine two given strings (lowercase). If there are any double character in new string then omit one character

0

Write a C# Sharp program to combine two given strings (lowercase). If there are any double character in new string then omit one character

Sample Output:

abcat
pythonphp
phphp

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("abc", "cat"));
            Console.WriteLine(test("python", "php"));
            Console.WriteLine(test("php", "php"));
            Console.ReadLine();
        }

 public static string test(string s1, string s2)
        {
             if (s1.Length < 1)
            {
                return s2;
            }

            if (s2.Length < 1)
            {
                return s1;
            }

            return !s1.EndsWith(s2.Substring(0, 1)) ? s1 + s2 : s1 + s2.Substring(1);
        }
   }
}

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