jeudi 5 novembre 2015

Splitting a text file where the information are separated in different lines

So, I have a text file where the information are separated by the enter key (I don't know how to explain, I will paste the code and some stuff).

cha-cha
Fruzsina
Ede
salsa
Szilvia
Imre

Here's how the text file looks like, and I need to split it into three parts, the first being the type of the dance, and then dancer 1 and dancer 2.

using System;
using System.Collections.Generic;
using System.IO;

namespace tanciskola
{
    struct tanc
    {
        public string tancnev;
        public string tancos1;
        public string tancos2;
    }
    class Program
    {

        static void Main(string[] args)
        {
            #region 1.feladat
            StreamReader sr = new StreamReader("tancrend.txt");
            tanc[] tanc = new tanc[140];
            string[] elv;
            int i = 0;
            while (sr.Peek() != 0)
            {
                elv = sr.ReadLine().Split('I don't know what goes here');
                tanc[i].tancnev = elv[0];
                tanc[i].tancos1 = elv[1];
                tanc[i].tancos2 = elv[2];
                i++;
            }
            #endregion
            Console.ReadKey();
        }
    }
}

Here is how I tried to solve it, although I don't really get how I should do it. The task is would be to display the first dance and the last dance, but for that I need to split it somehow.

Aucun commentaire:

Enregistrer un commentaire