Home > DeveloperSection > Forums > How to split a string stored in list<*> , then insert to same list using linq style or lambda ?
Royce Roy
Royce Roy

Total Post:149

Posted on    October-05-2013 2:27 AM

 ASP.Net ASP.Net 

 1 Reply(s)
 1490  View(s)
Rate this:

I have Writen o code using linq

var result=from m in driver_list select(m.Email,m.LisancePlate)

My code Output is like this

sample1@company.com;sample2@company.com----34 KZ 7898 sample3@company.com;sample2@company.com---- 34 TZK 6785

I want to a new output using my result like this sample1@company.com---34 KZ 7898 sample2@company.com---34 KZ 7898 sample3@company.com---34 TZK 6785 sample2@company.com---34 TZK 6785

Dag Hammarskjold
Dag Hammarskjold

Total Post:24

Posted on    October-05-2013 4:14 AM

string input = "sample1@company.com;sample2@company.com----34 KZ 7898 sample3@company.com;sample2@company.com---- 34 TZK 6785";
var result = string.Join(" ", Regex.Split(input, "\\s(?=\\S+@)")
                                var s = x.Split(new string[] {";","----"}, StringSplitOptions.RemoveEmptyEntries);
                                return string.Format("{0}---{2} {1}---{2}",s[0],s[1],s[2]);

Don't want to miss updates? Please click the below button!

Follow MindStick