vb.net - Populate an Array of Structure Variables by Reading a Delimited Text File -


i have text file called games.txt contains details of many computer game matches. each line represents:

player1score, player1name, player1age, player 2score, player2name, player2age  

here example of 3 lines (there total of 150):

1, john, 32, 5, albert, 54 3 lisa, 33, 2, michael, 36 4 jessica, 24, 1 robert, 32 

i want assign them structure array in each element has 6 member variables using streamreader. here structure variable:

structure gamedetails     public player1score integer     public player1name string     public player1age integer     public player2score integer     public player2name string     public player2age integer end structure 

i know using comma delimiter, can record each variable different element in array:

dim game() string game() = infile.readline.split(","c) 

which result in each element being assigned in way:

game(0) = 1  game(1) = john  game(2) = 32 

etc..

is there way can directly assign member variables each element? maybe each comma separates member variable, , new line means new element? unfortunately, not familiar syntax/commands not know how approach this.

note cannot hard-code application designed take data .txt.

could try creating method part of structure goes this:

public sub maplineentry(targetline() string)     player1score = cint(targetline(0))     player1name = targetline(1)     player1age = cint(targetline(2))     player2score = cint(targetline(3))     player2name = targetline(4)     player2age = cint(targetline(5)) end sub 

you want make sure string array has correct number of elements, start.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -