HOW TO SPLIT A STRING STORED IN LIST<*> , THEN INSERT TO SAME LIST USING LINQ STYLE OR LAMBDA ?

Royce Roy

Total Post:149

Points:1043
Posted by  Royce Roy
 1568  View(s)
Ratings:
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

  1. Dag Hammarskjold

    Post:24

    Points:168
    Re: How to split a string stored in list<*> , then insert to same list using linq style or lambda ?

    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+@)")
                                 .Select(x=>{
                                    var s = x.Split(new string[] {";","----"}, StringSplitOptions.RemoveEmptyEntries);
                                    return string.Format("{0}---{2} {1}---{2}",s[0],s[1],s[2]);
                                 }).ToArray());//

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!