I am using TextFieldParser to parse the Subject and Issuer fields of an X509 certificate. For instance, if you look at the certificate on https://facebook.com, you would see
CN=*.facebook.com,O="Facebook, Inc.",L=Menlo Park,S=CA,C=US
Of course it'd be simple to split that line on commas, were it not for those pesky quotation marks. So I have to escape those. That's why I wanted to use TextFieldParser. My code:
string[] subjectPieces = null;
using (MemoryStream memStream = new MemoryStream(Encoding.ASCII.GetBytes(cert.Subject)))
using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(memStream))
{
parser.SetDelimiters(",");
parser.HasFieldsEnclosedInQuotes = true;
subjectPieces = parser.ReadFields();
}
When this code runs, subjectPieces
will return:
CN=*.facebook.com
O="Facebook
Inc."
L=Menlo Park
S=CA
C=US
As you can see, it gave no regard to the field enclosed in quotation marks at all. I might as well have just used string.split(',')
.
I have tried setting HasFieldsEnclosedInQuotes
to both true and false, with no effect. I have tried multiple character encodings for the stream, with no effect.