Using a TextFieldParser from Microsoft.VisualBasic.FileIO it is possible to parse a CSV file like below:
using (TextFieldParser parser = new TextFieldParser(CSVPath))
{
parser.TextFieldType = FieldType.Delimited;
parser.SetDelimiters(",");
parser.HasFieldsEnclosedInQuotes = true;
while (!parser.EndOfData) { string[] fields = parser.ReadFields(); }
}
However this relies on initialising the TextFieldParser with a CSV file path. Is it possible to have the same effect but while passing in a string that contains the data record itself?
For example with a CSV data record with the value of Data1,6.5,"Data3 ""MoreData"""
(note the last data enclosed in quotes because of the escaped quotation marks) saved in a string variable, could I convert the data to a string array like this:
[0] = "Data1"
[1] = "6.5"
[2] = "Data3 \"MoreData\""