alostr
alostr

Reputation: 170

linq SelectMany and Regex.Split clr

I have a list of strings, that each string needs to split by a regex, than kept in the same list.

List<string> a = new List<string>();
a.Add("big string with a lot of words");
a=a.SelectMany(item=> Regex.Split("\r\n",item)).ToList();

I just want to make sure that this will not reorder the parts of the string that were created?

Is there a web site that has information about methods runtime and compiler optimizations?

Thanks

Upvotes: -1

Views: 773

Answers (1)

p.s.w.g
p.s.w.g

Reputation: 148980

With Linq-to-Objects, it will not re-order the elements of the result set unless you call OrderBy or OrderByDescending.

However, I wouldn't use regular expressions for this, a simple string.Split would do just fine:

List<string> a = new List<string>();
a.Add("big string with a lot of words");
a = a.SelectMany(item => item.Split(new[] { "\r\n" }, StringSplitOptions.None)).ToList();

Upvotes: 1

Related Questions