Write a C# Sharp program to create a new string from a give string where a specified character have been removed except starting and ending position of the given string

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

Write a C# Sharp program to create a new string from a give string where a specified character have been removed except starting and ending position of the given string

Sample Output:

xHix
abxdddca
xajhtrb

الأجوبة

using System;
using System.Linq;

namespace exercises
{
   class Program
    {
       static void Main(string[] args)
        {
            Console.WriteLine(StringX("xxHxix", "x"));
            Console.WriteLine(StringX("abxdddca", "a"));
            Console.WriteLine(StringX("xabjbhtrb", "b"));
            Console.ReadLine();
        }

        public static string StringX(string str1, string c)
        {
              for (int i = str1.Length - 2; i > 0; i--)
            {
                if (str1[i] == c[0])
                {
                    str1 = str1.Remove(i, 1);
                }
            }

            return str1;
        }
    }
}
هل كان المحتوى مفيد؟

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

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