C#C
C#3y ago
razeedazee

❔ .NET split string that is in a list

I have this (possibly horrible) code that works

        private void buttonInstanceSearch_Click(object sender, EventArgs e)
        {
            string searchInfo = textBoxSearch.Text;
            string searchDir = Directory.GetParent(AppContext.BaseDirectory).Parent.FullName + @"\instances";
            listBoxSearch.Items.Clear();

            var list_of_files_that_match = Directory.EnumerateFiles(searchDir, "README.md", SearchOption.AllDirectories).Where(delegate (string t)
            {
                return File.ReadAllText(t).Contains(searchInfo, StringComparison.CurrentCultureIgnoreCase);
            }).ToList();

            foreach (var value in list_of_files_that_match)
            {
                listBoxSearch.Items.Add(value);
            }
        }




The output is a list of full path to a file. I would like to split/remove the /README.md from the results. is this possible?
image.png
Was this page helpful?