I want to read values from text file and insert them to 2 arrays, the first column to one array and the second column to another array.
For example:
Text file: 0x223 0x2342342 0x21323 0x983298 0x908938 0x8382AA arr1 : 0x223, 0x21323 , 0x908938 arr2 : 0x2342342,0x983298,0x8382AA
How can I do it?
This question is related to
c#
string[] lines = File.ReadAllLines("sample.txt"); List<string> list1 = new List<string>(); List<string> list2 = new List<string>(); foreach (var line in lines) { string[] values = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); list1.Add(values[0]); list2.Add(values[1]); }
var Text = File.ReadAllLines("Path"); foreach (var i in Text) { var SplitText = i.Split().Where(x=> x.Lenght>1).ToList(); //@Array1 add SplitText[0] //@Array2 add SpliteText[1] }
Source: Stackoverflow.com