CopyPastehas never been so tasty!

Remove given String from string array in c#

by anonymous

  • 0
  • 0
  • 0
93 views

Remove given String from string array in c#

String ArrayString Arrays are used to store more than one string. We create and declare string arrays like that: 

string[] arr1 = new string[] { "one", "two", "three" };

 String.Remove methodString.Remove method is used to delete a value which we want to remove from a given string array.

Removal of Specified String in String Array

 We can remove a specified string in the string array by using String.remove method.

 

 Code

 using System.Collections;

using System.IO;

using System.Text.RegularExpressions;

 class Program

    {

        static void Main(string[] args)

        {

             String[] array = { "1", "2", "3", "4", "5", "6" };

             String hc = InputRemove("4", array);

             if (hc.Equals(""))

            {

                Console.WriteLine("input String has Been Removed");

                 Console.ReadLine();

             }

         }

       public static String InputRemove(string input, params String[] values)

       {

           string specified = input;

           foreach (string removal in values)

           {

               int i;

               while ((i = specified.IndexOf(removal)) > -1)

               {

                   specified = specified.Remove(i, removal.Length);

                 }

             }

  return specified;

     }

    }

Add A Comment: