I got function for finding word in text with indexof its returning list of objects with fields word and quantity,i want to use that function for different text and words to so im creating task and getting IndexOutOfRange on that line :
var r = Check_text(tnw.text[i], word);
For more understand thats my 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 anyone tell me solution for this problem?and what am i doing wrong there. Also there is part with 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);
for (var i = 0; i < 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);