.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Split a string in C#.net

Posted By:Narayanan       Posted Date: October 10, 2011    Points: 200    Category:    URL: http://www.dotnetspark.com  

Now, we discuss about How to split a string using "Split" Method in C#.net.
 

Split Method in C#.net

 

Part 1:

    Here, we discuss about Sentence to words.

 

   #region Declare a sentense in a String variable

            String  InputValue = "I can do it";

            #endregion Declare a sentense in a String variable

            #region Split a string portion

            string[] Splitwords = InputValue.Split(' ');

            #endregion Split a string portion

            #region Result

            foreach (string Result in Splitwords)

            {

                MessageBox.Show(Result);

            }

            #endregion Result

Result:

 I

Can

Do

it

 

Part 2:

   Here, we discuss about how to split a File path  using Split method

      #region Declare a sentense in a String variable

            String InputValue = @"C:\Documents and Settings\Narayanan\My Documents\Downloads\10.1.1.18.9302.pdf";

            #endregion Declare a sentense in a String variable

            #region Split a string portion

            string[] Splitwords = Regex.Split(InputValue, @"\\");

            #endregion Split a string portion

            #region Result

            foreach (string Result in Splitwords)

            {

                MessageBox.Show(Result);

            }

            #endregion Result

 

 

 

 

 

 



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend