Coding Villa

Remove given String from string array in c#

Author : Hassan Shafiq

Share with Friends
Views : 761
Ratings : 5
Bookmarks : 1
Farourities : 1

Description


In this simple article you will learn that how we can remove given String from string array in c#.


Advertisements


 

 

String Array

 

String 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 method

 

String.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;

        }

    }

 

 C++ Printed and Ebooks (Buy Now with special discounts)



Article Tags
Share with Friends

Comments




Leave a Reply

Name (required)  
Mail (will not be published) (required)   
 
Enter This Code
Captcha
 

Advertisements

Article Categories

.NET


Databases


Mobile Development


Operating Systems


Web Development


Coding Villa on Facebook