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

  • برمجة سي شارب
  • برمجة

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

الأجوبة

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);
        }
   }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...