'How to convert the specific law of one-dimensional array into two-dimensional array?

Like this

string[]  strarry = [12, 34, A1, FE, 12, 34, EA, 0, FE]

12 is the beginning , FE is the end, Turn into

string strarry = [[12,34,A1,FE], [12,34,EA,0,FE]];

The distance from 12 to FE is not necessarily fixed (4)

How can I do it? Thank you



Solution 1:[1]

I am not sure how applyable this code is for you, but maybe it gets you somewhere. Best of luck!

        var strarry = "12, 34, A1, FE, 12, 34, EA, 0, FE";
        var splittedArrays = strarry.Split(", FE", StringSplitOptions.RemoveEmptyEntries);

        for (int i = 0; i < splittedArrays.Length; i++)
        {
            if (splittedArrays[i][0].Equals(','))
            {
                splittedArrays[i] = splittedArrays[i].Substring(2);
            }

            splittedArrays[i] += ", FE";
            Console.WriteLine(splittedArrays[i]);
        }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Patrick