I need to find in which lines of both text files is my longest text fragment. I found it, but I don't know how to find in which lines is my text fragment. Maybe I need to change my ReadFile method somehow?
string[] Fragment(string[] wordsWithSeparatos1, string[] wordsWithSeparators2)
{
int place = 0;
string[] fragment = new string[1000];
for (int i = 0; i < wordsWithSeparatos1.Length; i++)
{
for (int j = 0; j < wordsWithSeparators2.Length; j++)
{
if (wordsWithSeparatos1[i] == wordsWithSeparators2[j])
{
fragment[place] += wordsWithSeparatos1[i] + ' ' ;
i++;
}
else
{
if (fragment[place] != null)
{
place++;
}
}
}
}
return fragment;
}
void LongestFragment(string[] fragment)
{
foreach (var item in fragment.OrderByDescending(x => fragment.Length).Take(1))
{
Console.WriteLine(item);
}
}
string[] ReadFile(string fn)
{
char[] space = { ' ' };
string lines = File.ReadAllText(fn, Encoding.GetEncoding(1257));
string[] wordsWithSeparators = new string[1000];
wordsWithSeparators = lines.Split(space, StringSplitOptions.RemoveEmptyEntries);
return wordsWithSeparators;
}
Text1.txt: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Text2.txt: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.