linq SelectMany and Regex.Split clr

747 Views Asked by At

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

1

There are 1 best solutions below

1
p.s.w.g On

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();