help with inport csv file to my C# program
-
hi 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 ?
-
hi 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 ?
-
hi 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 ?
-
hi 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 ?
goldsoft wrote:
code ,name ,price "101010","computer 12,200.00","200$"
For this there's a solution, You can use regex to use. follow the step 1. Replace the ',' Char inside "abc,xyz" with some Character not conflicted with CSV delimeter, Say @, using Regex. 2. Now you will get exact split in three words, Once splitted further Replace the '@' with ',' in Splitted string.
goldsoft wrote:
code ,name ,price 101010,computer 12,200.00,200$ if i get this type of csv:
For this I don't think of any Intelligent detection.
Regards, Hiren.
My Recent Article: - Way to know which control have raised PostBack
My Recent Tip/Trick: - Remove HTML Tag, get plain Text -
hi 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 ?
-
hi 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 ?
Yeah, what they said, especially Rive :thumbsup: .
goldsoft wrote:
WI[0].Trim().ToString();
You don't need the ToString.
-
Thank you. :thumbsup:
-
Thank you. :thumbsup:
10! :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
hi 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 ?
-
Thank you. :thumbsup:
Well done! :-D You should be seeing a small spike in your reputation score today...
Will Rogers never met me.