HI everyone,
i have to split a string like "CD-016 - Samina Joshi" into string1="CD-016 " and string2="Samina Joshi". how is it possible to do.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Praneeth KumarPosted Jun 13, 2011, 3:11 AM
string str = "CD-016 - Samina Joshi";
string str1 = str.Substring(0, str.IndexOf(" - "));
string str2 = str.Substring(str.IndexOf(" - ") + 3, str.Length - str.IndexOf(" - ") - 3);
VulpesPosted Jun 13, 2011, 6:19 AM
Suthish NairPosted Jun 13, 2011, 5:37 AM
VulpesPosted Jun 13, 2011, 4:27 AM
string[] items = str.Split(new string[]{" - "}, StringSplitOptions.None);
Praneeth KumarPosted Jun 13, 2011, 4:24 AM
Suthish NairPosted Jun 13, 2011, 4:23 AM
string[] lines = System.Text.RegularExpressions.Regex.Split("CD-016 - Samina Joshi", " - ");