Answer the question
In order to leave comments, you need to log in
How, when reading from a file of an array of strings, to discard and ignore one of the occurrences?
Hello everyone, I'm confused and can't solve the following:
there is a text file that contains the lines:
one two three ten lot soap test
five good lot test bread seven one
...
Answer the question
In order to leave comments, you need to log in
var line = reader.ReadLine();
var words = line.Split(" ".ToCharArray()).ToList();
words.RemoveAt(4);
var result = string.Join(" ", words);
If you are reading the file line by line and want each word to be unique? then why not look towards collections. I think Set will do here about Collections C#
static void Main()
{
string[] lines = System.IO.File.ReadAllLines(@"e:\temp\test.txt");
List<string> result = new List<string>();
foreach (string line in lines)
{
string[] split = line.Split(new Char[] { ' ' });
foreach (string spl in split)
{
result.Add(spl);
result.Remove("много");
}
foreach (string res in result)
{
Console.WriteLine(res + " - " + result.Count);
}
}
Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question