c# - How to parse delimited files to be compared -


there text file formatted example below need search students class name:

michael | straham | eng101(4.0) | mth303 jacob | black | sci 210 (2.3) | eng101 ian | summers | mth303(3.30) | sci 210 

the delimited symbols ( | )

the class names "eng101, sci210, mth303." search each line text class name , somehow index them can compared. end result this:

eng101: michael straham, jacob black 

please assist. in advance!

i'm assuming you're reading in input line line.

you can use string.split() accomplish (the first part of) trying do.

for example, following code

string s1 = "michael | straham | eng101(4.0) | mth303"; char[] separators = { '|' }; string[] values = s1.split(separators); 

would give array of 4 strings ( "michael", "straham", "eng101(4.0)", "mth303"). can analyze values array see in class. i'd have code looks (in pseudocode):

foreach (line in input) {      string s1 = line;     char[] separators = { '|' };     string[] values = s1.split(separators);      string firstname = values[0];     string lastname = values[1];      (i = 2, < values.length)     {         if (values[i] looks "eng101")         {            add firstname lastname "eng101" student list         }         else if (values[i] looks "mth303")         {            ....         }         ....     } } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -