How to split a file line without using Substrings in C #?

0

I have created a file where I save line-by-line data as morada|nome|telefone|nif , meaning each variable stored in the file is divided by | .

I remember there being a method of dividing this line into 4 to add to a dataGridView without using Substrings or IndexOf ... Is there any faster way to do it?

For example, I want to add morada to one column, nome to another, and so on ...

    
asked by anonymous 27.09.2017 / 10:39

1 answer

5

How about the Split method?

string s = "morada|nome|telefone|nif";
string[] colunas = s.Split('|');
Console.WriteLine("{0} {1} {2} {3}", colunas[0], colunas[1], colunas[2], colunas[3]);
  

Example working on repl.it

Reference

27.09.2017 / 11:03