I have a text file which is and extract from database. Each line is one record and I'm trying to parse it.
Here is the troublesome part after some anonymisation:
"CODE0001" "Name1 " 14.46 0.05
"CODE0002" "Name2" 17.37 0.05
"CODE0003" "Name3" 22.66 0.05
It may have strings or numbers, separated by tabulators. Strings are in brackets. Unfortunately tabulators may happen also in names like "Name1 " which I learnt by getting some parse errors.
My first code was:
string[] articles = File.ReadAllLines(myFile);
char[] separators = { '\t' };
for (int i = 0; i < articles.Length; i++)
{
string[] article = articles[i].Split(separators);
string code = article[0];
string name = article[1];
string val1 = article[2];
string val2 = article[3];
//do something with these values
}
But if there is a tabulator in some name it goes wrong.
How could I split and parse these lines ignoring tabs in names (surrounded by brackets) and detecting only true delimiters?