Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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;
        }
    }
}

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