Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

help with inport csv file to my C# program

Tags:

c#

csv

winforms

i try to inport csv file to my database in my C# winform program.

for example the csv file:

code  ,name    ,price
101010,computer,200$

and i done this:

char[] BI = { ',' };
string[] WI = TEMP.Split(BI);
A = WI[0].Trim().ToString();
B = WI[1].Trim().ToString();
C = WI[2].Trim().ToString();

but what i can do if the name contain (,) ?

for example

code  ,name              ,price
101010,computer 12,200.00,200$

if i get this type of csv:

code    ,name                ,price
"101010","computer 12,200.00","200$"

how to deal with this ?

like image 959
Gold Avatar asked Nov 26 '25 07:11

Gold


1 Answers

The best thing to do is not roll your own csv and use a existing free library. I recommend FileHelpers.

EDIT:

Here is a fun little read, I bet you are on step 2 or step 3.

like image 55
Scott Chamberlain Avatar answered Nov 27 '25 21:11

Scott Chamberlain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!