So there are loads of posts on here that note rather than rolling my own csv parser I ought to use either the Vb.Net TextFiledParser.
I tried it but, and please tell me if I'm wrong, it'll parses based on a single delimeter.
So if I have an address field "Flat 1, StackOverflow House, London" I get three fields. Unfortunately that's not what I want. I need everything in a given cell to remain as a single item in the array.
So I started to write my own RegEx as follows :
var testString = @"""Test 1st string""" + "," + @"""Flat 1, StackOverflow House, London, England, The Earth""" + "," + "123456";
var matches = Regex.Matches(chars, @"""([^""\\])*?(?:\\.[^""\\]*)*?""");
var numbers = Regex.Matches(chars, @"\d+$");//only numbers
Assert.That(results.Count(), Is.EqualTo(3));
Assert.That(secondMatch.Count, Is.EqualTo(1));
The first assertion fails as the string "123456" is not returned. The expression only returns "Test 1st string" and "Flat 1, StackOverflow House, London, England, The Earth"
What I'd like is for the regex to return everything quoted\escaped, and numbers.
I don't control the data but figure strings will all be quoted\escaped and numbers won't.
I'd really appreciate some help as I'm going around in circles trying third party libraries without much success.
Needless to say string.split doesn't work in the case of addresses, and http://www.filehelpers.com/ doesn't seem to account for such examples.