Recent

6/recent/ticker-posts

Header Ads Widget

Split Function on C Sharp

Split Function in C sharp

the string has many characters in the single world like a comma(,), Space( ) etc. String class has Split() function to separate word even if we want to just one part from the string. It Returns the string array.
I am using Dot net 4.5 it is also used in later version

Split function that is based on comma

using System;

class Program
 {
      Static void Main()
        {
            string fruits="Apple,Mango,Jack Fruit,Orange";
            //now split the fruit name by ','
            //this code separate all the fruit name
           string[]fruit=fruits.Split(',') //Split function take                //char parameter
            foreach(string f in fruit)
            {
                  Console.WriteLine(f);
            }
        }
 }

Now Output is Like this

Apple
Mango
Jack Fruit
Orange

Here for example 
variable fruits store the "Apple,Mango,Jack Fruit,Orange" word and 
after split fruits it will store in fruit with array 




Post a Comment

0 Comments