Tuesday, November 16, 2010

How to do split data based on delimiter with c Sharp code?

With below code we can split any data based on separator.

string path="C:\\test\\file\\TestResults";
int a = path.IndexOf("\\TestResults");
string ss = path.Substring(0, a - 1);
MessageBox.Show(ss);

Output Result:- C:\\test\\file
or

we can do split data with below code also

string path="C:\\test\\file\\TestResults";
string[] ss = new string[] { "\\TestResults" };

string[] st1 = path.Split(ss, StringSplitOptions.RemoveEmptyEntries);
MessageBox.Show(""+st1[0]);

No comments:

Post a Comment