I have a .csv file(I have no control over the data) and for some reason it has everything in quotes.
"Date","Description","Original Description","Amount","Type","Category","Name","Labels","Notes"
"2/02/2012","ac","ac","515.00","a","b","","javascript://"
"2/02/2012","test","test","40.00","a","d","c",""," "
I am using filehelpers and I am wondering what the best way to remove all these quotes would be? Is there something that says “if I see quotes remove. If no quotes found do nothing”?
This messes with the data as I will have "\"515.00\"" with unneeded extra quotes(especially since I want in this case it to be a decimal not a string”.
I am also not sure what the “javascript” is all about and why it was generated but this is from a service I have no control over.
edit
this is how I consume the csv file.
using (TextReader textReader = new StreamReader(stream))
{
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
object[] transactions = engine.ReadStream(textReader);
}
You can use the
FieldQuotedattribute described best on the attributes page here. Note that the attribute can be applied to any FileHelpers field (even if it typeDecimal). (Remember that the FileHelpers class describes the spec for your import file.. So when you mark aDecimalfield asFieldQuoted, you are saying in the file, this field will be quoted.)You can even specify whether or not the quotes are optional with
Here is a console application which works with your data:
(Note, your first line of data seems to have 8 fields instead of 9, so I marked the
Notesfield withFieldOptional).