I was working with this and came across a new problem as I needed to incorporate a jagged array, so I tried modifying this code like so..
string y = "{10} red30, {20} blue12, {30} green90, {40} yellow13 : {15} axe,
{25} frog, {33} sandwich, {55} spinach : ...." and so on.
int[][] Odds = y.Split(':').Select(t => Regex.Matches(t, @"(?<={)\d+(?=})"))
.Cast<Match>() .Select(m => int.Parse(m.Value)) .ToArray();
with a new string that had a “:” as a separator between each new array. it gives me the error of “cannot implicitly convert type ‘int[]’ to ‘int[][]’
That’s beccause the
Matchesmethod doesn’t return aMatchobject, it returns aMatchCollectionobject. You have to get theMatchobjects from each collection and parse the values, then you can turn those into an array: