c# - System.IndexOutOfRangeException in function for findinding words in text with IndexOf -


i got function finding word in text indexof returning list of objects fields word , quantity,i want use function different text , words im creating task , getting indexoutofrange on line :

var r = check_text(tnw.text[i], word); 

for more understand thats function:

    public static list<wordsinf> check_text(string text,string[] words)     {         list<wordsinf> result = new list<wordsinf>();         var pos = 0;         var quantity = 0;         foreach (string wf in words)         {             pos = 0;             quantity = 0;             while (true)             {                 var foundpos = text.indexof(wf, pos);                 if (foundpos == -1)                 {                     break;                 }                 pos = foundpos + 1;                 if (foundpos >= 0)                 {                     quantity++;                 }             }             result.add(new wordsinf(wf, quantity));         }         return result;     } 

thats example of inputs:

  -     word    {string[2]} string[]             [0] "asd"   string             [1] "qwe"   string     -       tnw.text    {string[2]} string[]             [0] "asd qwe ssd www "  string             [1] "asd asd qwe sss "  string 

can tell me solution problem?and doing wrong there. there part tasks:

 var numtasks = tnw.text.length;         analyzeobj[] analyzeobjs = new analyzeobj[numtasks];         var word = tnw.words.split(',');         task[] tasks = new task[numtasks];         console.writeline(word);         console.writeline(tnw.text);        (var = 0; < numtasks; i++)         {             tasks[i] = new task(() => {                 var r = check_text(tnw.text[i], word);                 analyzeobjs[i].text = tnw.text[i];                 analyzeobjs[i].wordinfos=r;                 analyzeobjs[i].id=guid.newguid();                 analyzeobjs[i].findwords = word;             });             tasks[i].start();          }         task.waitall(tasks); 

   (var = 0; < numtasks; i++)         {             var i1 = i;             tasks[i] = new task(() =>             {                 var item = new analyzeobj();                 var r = check_text(tnw.text[i1], word);                 item.text = tnw.text[i1];                 item.wordinfos = r;                 item.id = guid.newguid();                 item.findwords = word;                 analyzeobjs.add(item);             });             tasks[i1].start();         } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -