Changing delimter does not remove default delimiter #259
Replies: 11 comments 1 reply
-
Can you give me some code and data examples? This works for me: void Main()
{
using( var stream = new MemoryStream() )
using( var writer = new StreamWriter( stream ) )
using( var reader = new StreamReader( stream ) )
using( var csv = new CsvReader( reader ) )
{
writer.WriteLine( "Id\tCost" );
writer.WriteLine( "1\t1,234" );
writer.WriteLine( "2\t2,356" );
writer.Flush();
stream.Position = 0;
csv.Configuration.Delimiter = "\t";
csv.Configuration.RegisterClassMap<TestMap>();
csv.GetRecords<Test>().Dump();
}
}
public class Test
{
public int Id { get; set; }
public decimal Cost { get; set; }
}
public class TestMap : CsvClassMap<Test>
{
public TestMap()
{
Map( m => m.Id );
Map( m => m.Cost ).TypeConverterOption( System.Globalization.NumberStyles.Currency );
}
} |
Beta Was this translation helpful? Give feedback.
-
Code: Private Function ReadBillDetails(ByVal filename As String) As List(Of EzyPayBillDetail)
Using reader As New StreamReader(filename)
Dim csv As New CsvReader(reader)
csv.Configuration.Delimiter = vbTab
csv.Configuration.HasHeaderRecord = True
Return csv.GetRecords(Of EzyPayBillDetail)().ToList()
End Using
End Function
Workaround: |
Beta Was this translation helpful? Give feedback.
-
I'm not able to reproduce this. Here is example code. void Main()
{
using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
using( var writer = new StreamWriter( stream ) )
using( var csv = new CsvParser( reader ) )
{
writer.WriteLine( "PrinAcc\tDistAccId\tDistId\tEzypay#\tPrinNo\tLastName\tFirstName\tAmount\tDate\tStatusId\tStatus" );
writer.WriteLine( "21957\t106811\t2319767\t11059912\t30-06-2010\txxLastNamexx\txxFirstNamexx\t1,138.50\t10/04/2014\t3 \tCleared" );
writer.Flush();
stream.Position = 0;
csv.Configuration.Delimiter = "\t";
while( true )
{
var row = csv.Read();
if( row == null )
{
break;
}
row.Dump();
}
}
} I'm getting all fields as expected. Do you have a real set of data that you can send me that I can test with? |
Beta Was this translation helpful? Give feedback.
-
Sure Josh. Can I send it to you privately? |
Beta Was this translation helpful? Give feedback.
-
Sure. Can you email it to me? |
Beta Was this translation helpful? Give feedback.
-
Did you end up sending this? If so, I don't think I received it. If this is still and issue, send the test file my way, and post on here to make sure I got it. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Hi, This is still a problem for me. But I have a text: "Tidningar, facklitteratur" which has coma and is putting the text "facklitteratur" in a separated column |
Beta Was this translation helpful? Give feedback.
-
Can you create a failing example for me? This works. void Main()
{
using (var writer = new StringWriter())
using (var csv = new CsvWriter(writer))
{
csv.Configuration.Delimiter = ";";
csv.WriteField("1");
csv.WriteField("2a, 2b");
csv.WriteField("3");
csv.NextRecord();
writer.ToString().Dump();
}
} Output:
|
Beta Was this translation helpful? Give feedback.
-
Yes, and when you open it in Excel, it's messed up |
Beta Was this translation helpful? Give feedback.
-
@djanjicek What is messed up? |
Beta Was this translation helpful? Give feedback.
-
@JoshClose propose to close? |
Beta Was this translation helpful? Give feedback.
-
I am reading tab-delimited text files. Set the delimiter to 'tab' and all is good until there is a comma in a number to read. CsvHelper appears to read the comma as a delimiter and then column mapping fails.
Of course, commas commonly appear in numbers so this is a regular problem.
Beta Was this translation helpful? Give feedback.
All reactions