How to process delmited file where there is a "=" to represent data as text #2366
bravo-2007
started this conversation in
General
Replies: 1 comment
-
|
If the fields are always escaped with quotes, you can trim the fields and put void Main()
{
var text = """
Id,Name
1,="one"
2,="two"
""";
using var reader = new StringReader(text);
using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture)
{
TrimOptions = TrimOptions.Trim,
WhiteSpaceChars = ['='],
});
csv.Context.RegisterClassMap<FooMap>();
var records = csv.GetRecords<Foo>();
records.Dump();
}
class Foo
{
public int Id { get; set; }
public string Name { get; set; }
}
class FooMap : ClassMap<Foo>
{
public FooMap()
{
Map(m => m.Id);
Map(m => m.Name);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a csv file that i need to process. The format is
"Field1", "Field 2", "Field 3"
"row1val1",="row1val2.0","row1val3"
"row2val1",="row2val2.0","row2val3"
When i process this file, i am getting bad data error. can someone please suggest how to configure reader for this?
Beta Was this translation helpful? Give feedback.
All reactions