0

My question is how can i split the words inside this .txt file

string filePath = @"..\..\Tekst.txt";
        List<string> lines = new List<string>();

        lines = File.ReadAllLines(filePath).ToList();

        foreach (string line in lines)
        {
            Console.WriteLine(line);
        }

Here is how i want to split it. I want it to split every time there is space, ",", ".", "!" and "?". But when i do that it comes out with an error

        string[] wordsArray = lines.Split(' ', ',', '.', '!', '?');

        foreach (string line in wordsArray)
        {
            Console.WriteLine(line);
        }
New2200
  • 3
  • 4
  • What does the contents of `Tekst.txt` look like? Can you post a few sample lines along with desired output/result? – Mathias R. Jessen Dec 08 '20 at 09:54
  • 1
    "*Here is how i tried to split inside it*" so what happened, did you get an error, did you pc catch fire? – TheGeneral Dec 08 '20 at 09:55
  • Please read [ask] – TheGeneral Dec 08 '20 at 09:56
  • I got an error when i tried to split it but i can read the entire file. – New2200 Dec 08 '20 at 09:58
  • share the sample content and how you want to split? the question need to share more details – Aqdas Dec 08 '20 at 09:59
  • What is the error? – Captain Kenpachi Dec 08 '20 at 10:04
  • Severity Code Description Project File Line Suppression State Error CS1061 'List' does not contain a definition for 'Split' and no accessible extension method 'Split' accepting a first argument of type 'List' could be found (are you missing a using directive or an assembly reference?) Carbon BLack C:\Users\drama\source\repos\Carbon BLack\Program.cs 22 Active – New2200 Dec 08 '20 at 10:06
  • 1
    That's because `lines` is a `List`, not a `string`. Only strings have a split method. Probably you need to loop through the lines and run `split` on each individual line. – ADyson Dec 08 '20 at 10:06

0 Answers0