We had some interesting string as follows which need to split and take the desired portion. C#.Net provides special string function called Split, which helps you broke complex strings into fragments.
Here are our Stings look like
121 | Whole Sale Rate
131 | Retail Rate
We begin with initialization of string and then build separator array, then call the split method. I guess you are familiar with the string array if you don’t just look at the 3rd line.
string st=”121 | Whole Sale Rate”;
Here “|” is the separator
string[] separator= { “|” };
string []selRateStr = null;
Let’s split the string with Split, which is the function available with string object also with ToString() too.
selRateStr =st.Split(separator,StringSplitOptions.None);
the first element in the selRateStr will be 121, which can be accessed as selRateStr [0];
Here is the authentic link from MSDN which may help you to learn Split function in detail.