There is a task to read data from the .csv file, separated by a semicolon ';', into the array String ^.
The number of rows and columns is known; I create an array dynamically. There are as many rows and columns in the array as in the file. That is, should fit perfectly.

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { setlocale(LC_ALL,"Russian"); array<String^,2>^ basedfs; array<String^,2>^ basehw; basedfs=gcnew array<String^,2>(stringsdfs,lenghtdfs);//первый массив, размерность определена в этих переменных. basehw=gcnew array<String^,2>(stringshw,lenghthw);//второй try { StreamReader^ dfs=gcnew StreamReader("MSV-BD1.csv");//файл,из которого читаю данные for (int i=0;i<stringsdfs;i++){ for(int j=0;j<lenghtdfs;j++){ basedfs[i,j]=Convert::ToString(dfs->ReadLine()->Split(';'));//пытаюсь засплитить через точку с запятой } } delete dfs; } catch (...) { textBox1->Text="Файл не может быть открыт"; } textBox2->Text=basedfs[3,7];//но здесь выводит System.String[]. 

}

How to read the data?

  • CSV means comma-separated values, and you have a semicolon. This time. Then, is there any kind of escaping? In a real CSV, you can enclose the string in quotes, and the comma does not make much sense in it - and you? - VladD
  • There is a table in Excel. When saving, I specify the type of CSV files (comma delimited). When opening with a notepad, the table data is separated by ';'. I do not know why. In ordinary C ++ (in the console), everything was implemented quite simply. THERE requires a graphical shell - problems arose - anonim
  • In Russia, separated by a semicolon. The comma is occupied by real numbers. - pavelip
  • @pavelip: Format even in Africa format. Imagine that in Russia inside JPEG files all the characters “ , ” should be understood as “ . ". - VladD
  • @valentinn: The difference between C ++ and what you write is huge! You are not writing in C ++, but in a disgusting C ++ / CLI monster. If you're already writing to .NET, go to C #, otherwise the problems will be at every turn. - VladD 2:47 pm

1 answer 1

 using namespace System; using namespace System::IO; using namespace System::Collections::Generic; List<array<String^>^>^ list = gcnew List<array<String^>^>(); for each (String^ line in File::ReadLines("MSV-BD1.csv")) { list->Add(line->Split(';')); } array<String^>^ row = list[0]; // берем строку 0 String^ cell = row[0]; // берем ячейку 0 // количество элементов в строке int length = row->Length; // одной командой String^ cell = dynamic_cast<array<String^>^>(list[0])[0]; //Печать в консоль for each (array<String^>^ row in list) { for (int i = 0; i < row->Length; i++) { String^ cell = row[i]; Console::Write(cell + "\t"); } Console::WriteLine(); } 
  • Thanks, but how can I access this data? I then in the course of the program is required to compare them, search, and so on. Well, that is, with the array, I imagined how, by the indices you go through the cycle. How about here? - anonim
  • Added access to arrays - pavelip 2:13 pm
  • Thanks again. Can I have a couple of questions: 1. How did I understand from the Google List that is the dynamically expanding list itself? That is, I do not need dancings with a tambourine to find out how many lines and elements I have in a file? 2. You declared it, it turns out, how the list of arrays? and how long? Is he the type he decides? 3. What did you add: row array = is an array with list [0] elements? String ^ cell = row [0] - but this is what I did not understand at all. Is it the index of the element of the first array? Or how? - anonim
  • 1. Yes, List is dynamic, but responsible for strings. 2. As a list of pointers to an array of pointers to a string. 3. First we get 0 row, then we get 0 column from it. - pavelip
  • How difficult it is for perception: a list of pointers to an array of pointers to a string))) It works, not like mine) And how can I now work with this structure. Run for example on all elements, and find the right one? it turns out you need to create as many arrays as there are lines in the file. And as many variables as there are elements in the string - anonim