Write a C# Sharp program to combine two given strings. If the given strings have different length remove the characters from the longer string

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

Write a C# Sharp program to combine two given strings. If the given strings have different length remove the characters from the longer string

Sample Output:

abcbcd
PythonPython
JSon

الأجوبة

using System;

namespace exercises
{
   class Program
    {       
        static void Main(string[] args)
        {
            Console.WriteLine(test("abc", "abcd"));
            Console.WriteLine(test("Python", "Python"));
            Console.WriteLine(test("JS", "Python"));
            Console.ReadLine();
        }

  public static string test(string s1, string s2)
        {
            if (s1.Length < s2.Length)
            {
                return s1 + s2.Substring(s2.Length - s1.Length);
            }
            else if (s1.Length > s2.Length)
            {
                return s1.Substring(s1.Length - s2.Length) + s2;
            }
            else
            {
                return s1 + s2;
            }
        }
   }
}
هل كان المحتوى مفيد؟

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

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