There is a text document filled with a table of irregular verbs

  • to be was
  • become became become

etc

How to fill a two-dimensional array with this table so that it looks like:

string[,] verbs = { {"to be" , "was, were", "been", "Π±Ρ‹Ρ‚ΡŒ"}, {"become", "became", "become", "ΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒΡΡ"} ... }; 
  • one
    Do you have any divisor between the verbs in the line, for example, comma? - iluxa1810
  • No, because the string "was, were" has a comma and the program will write two lines instead of one. But you can add another separator, for example a point - Draktharon
  • I wrote the solution below, try it. Just replace the comma with any desired divider in the code. - iluxa1810
  • I need a two-dimensional array and not a list - Draktharon
  • You really need a list, believe me. A two-dimensional array in your situation is a very uncomfortable thing. - VladD

1 answer 1

It can be like this, provided that the divisor is a comma.

  string[] readText = File.ReadAllLines(path);//считываСм всС строки Π² массив List<string[]> res = new List<string[]>(); foreach (var line in readText)//ΠΏΠ΅Ρ€Π΅Π±ΠΈΡ€Π°Π΅ΠΌ строки массива { res.Add(line.Split(','));//ΠšΠ°ΠΆΠ΄ΡƒΡŽ строку сплитим ΠΈ ΠΏΠΎΠΌΠ΅Ρ‰Π°Π΅ΠΌ Π² список массивов. } 

If you do without a list, it will look something like this:

  string[] readText = File.ReadAllLines(path);//считываСм всС строки Π² массив string[][] res=new string[readText.Length][]; int i = 0; foreach (var line in readText)//ΠΏΠ΅Ρ€Π΅Π±ΠΈΡ€Π°Π΅ΠΌ строки массива { res[i] = line.Split(','); i++; } 
  • And how to address to the first element of the list, and in it to the third line? - Draktharon
  • As in the two-dimensional array res [0] [2] - iluxa1810