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

Asked

Viewed 68 times

0

I created a file where I store data row by row as morada|nome|telefone|nif, that is, each variable saved 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 Index... Is there any quicker way to be done?

For example, I want to add morada to a column, nome the other and etc...

  • And why not use Substring()? Want to do as?

1 answer

5

How about the method Split ?

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.