How to break a string in c#

{0 Comments}

To break string in Csharp we use split inbuilt function or method. We split the string on the basis of delimiter. In below code sample uses the space delimiter, that is found most in any string statement you can use other delimiter in place of space. Split function return result as an array so we assign returned result of split method. And then use for loop to access each array element one by one and use then according to our required logic. Have a look on the following code sample for better understanding.

 C# |  copy code |? 
1
string a = "this is long string which is going to split";//string going to split 
2
        string[] splited_Word = a.Split(' ');//use space as a delimiter.
3
        foreach (string word in splited_Word)
4
        {
5
           Response.Write("</br>"+word);
6
        }
7

Leave a Comment

Your email address will not be published.