c# - Parse fixed width, insert into array. How? -
i'm trying parse powerball lottery text file, add each of 6 columns own array , play around little bit.
here's example of data:
draw date wb1 wb2 wb3 wb4 wb5 pb pp 04/03/2013 35 08 12 01 06 03 03/30/2013 23 46 11 26 55 27 03/27/2013 43 48 07 37 52 16 03/23/2013 29 53 52 17 31 31 03/20/2013 43 17 14 13 54 15 03/16/2013 44 53 07 21 03 16 ...
here's had in mind:
int[] column1 = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int[] column2 = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int[] column3 = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int[] column4 = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int[] column5 = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int[] column6 = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
just need little hand parsing function. php's explode function nice.
basic mode of operation: split lines, split separator, work on data. simple parsing function might be:
var cli = new webclient(); var raw = cli.downloadstring("http://www.powerball.com/powerball/winnums-text.txt"); var lines = raw.split('\n'); var records = line in lines.skip(1) let parts = line.split(new char[] {' '}, stringsplitoptions.removeemptyentries) select new { date = datetime.parse(parts[0], cultureinfo.invariantculture), numbers = parts.skip(1).take(6).select(x => int.parse(x)) };
Comments
Post a Comment