Assuming you have read all the lines in the file into one big string:
private char[] splitChars = new char[] {' ', '\r', '\n'};
private UInt32[] col1;
private UInt32[] col2;
private void TranformToArraysOfUInt32(string rawFileData)
{
List<string> splitList = rawFileData.Split(splitChars, StringSplitOptions.RemoveEmptyEntries).ToList();
col1 = splitList
.Where
(
(str, index) => (index + 1) %2 == 1
)
.Select(n => Convert.ToUInt32(n, 16)).ToArray();
col2 = splitList
.Where
(
(str, index) => (index + 1) %2 == 0
)
.Select(n => Convert.ToUInt32(n, 16)).ToArray();
foreach (UInt32 theUInt in col1)
{
Console.WriteLine("col 1: 0x" + theUInt.ToString("X"));
}
foreach (UInt32 theUInt in col2)
{
Console.WriteLine("col 2: 0x" + theUInt.ToString("X"));
}
}</string>
This code splits the raw file data (Type string) into a generic List of Type string.
Then Linq is used:
1. the Where clause uses Linq's 'index property, and modulo, to select either every odd-numbered, or even-numbered, element in the List.
2. the Select clause handles the task of converting the hexadecimal string representations of a UInt to Type UInt32, creating a List of all them, which is converted into an Array.
Note that there is no
validation of elements being scanned here: if any element is not a valid representation of a UInt32, that's an error !
Experience suggests that some form of validation should take place: at the least the use of a try/catch block.
While you could use UInt32.TryParse inside the Linq code to exclude elements that are not in the correct format, there is a possible "structural" problem: Suppose one item is excluded: now your two "columns" do not have the same number of elements, which I would guess would create problems in your code.
The task of excluding both elements at the same index in the Columns if one is in the wrong format would probably require processing that did not use Linq. Or, possibly, making a preprocessing pass over the data just to exclude any possible pair of entries where one or both was incorrectly formatted.