item.Split not working

  • Thread starter Thread starter horatiu_alex
  • Start date Start date
H

horatiu_alex

Guest
I want to take the info from a listbox, remove unwanted words, and then write a coma separated row.

public void saveListButton_Click(object sender, EventArgs e)
{
const string sPath = (@"C:\Users\user\Desktop\Document.TXT");

System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
foreach (var item in usersListBox.Items)
{
item.ToString().Replace(" ", ",");
List<string> unwantedWords = new List<string> { "is", "a", "of" };
var linesSplitted = item.Split(",").ToList();
linesSplitted.Where(i => !unwantedWords.Contains(i)).ToList();
var wordsWithoutUnwantedWords = linesSplitted.Where(i => !unwantedWords.Contains(i)).ToList();
for (int i = 0; i < wordsWithoutUnwantedWords.Count; i++)
{
var isLastWord = i == wordsWithoutUnwantedWords.Count - 1;

Console.Write(wordsWithoutUnwantedWords);

if (!isLastWord)
{
Console.Write(",");
}
}


}

SaveFile.Close();

MessageBox.Show("Programs saved!");
}

But I get an error on this line:

var linesSplitted = item.Split(",").ToList();

Any suggesttions? Thanks!

Continue reading...
 
Back
Top