c# - Text File Storing Data -


i have text file read in (which not problem), file divided 3 sections each different heading i.e. block{a}, block{b} , block{c}.

after each block lines of text, each line contains word after "#" need capture.

the tricky bit words in block have second meaning or weighting. words in block have weighting of 1, whilst block b weighting 2 , block c weighting 3.

these weight values not present in text file , text file cannot edited include them.

so need method read data (not problem), check block in (look 'block{*}') store away word after '#' weighting (1 or 2 or 3).

i need suggestions best mechanism store data can compared text box updated character character.

the text box string compared (after each key press) words in text file or data extracted , if match, weighting value associated word used code.

first off, can create simple class store data

public class words {   public string word{get;set;}   public int weigth{get;set;} } 

then process file:

  var words = new list<words>();   string[] lines = file.readalllines("myfilename");   int weigth = 0;   foreach( var line in lines )   {     if (line == "block{a}") weigth = 1;     else if (line == "block{b}") weigth = 2;     else if (line == "block{c}") weigth = 3;     else words.add( new words{ word = line.replace("#",""), weigth = weigth});   } 

now, since have list in memory, lookups should quick. example find if have entries match written text, can this:

var matches = words.where(w => w.word.startswith(mytextbox.text)).orderbydescending(w => w.weigth); 

now matches contain list of words start same text written in textbox, , sorted words highest weight appear first in list.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -