How do I handle line breaks in a CSV file using C#? -
I have an Excel spreadsheet that is being converted into a CSV file in C #, but the problem with handling the line breaks For example: "John", "23", "555-5555" "Peter", "24", "555-5 555" "Mary," 21 "," 555- 5555 " >
When I read the CSV file, if the record does not start with double quote (") then a line break is by mistake and I have to remove it. I have some CSV They are readers but I am worried that they will fail on line breaks.
How should I manage these line breaks?
Many thanks to everyone a lot for your help.
Whatever has been done so far, my record format has been corrected and all
JTW; ...; Begins with .... ...; JTW; ...; ...; .... JTW; ....; ... .. .. .. ... ... (Wrong record, line bar inserted) JTW; ...; ...
So I have the in each row's [3] position;
If I write the truth, then attach to remove the last * line-break from a liar.)
Now I am having trouble because IM is saved as a TST file Used to be.
By the way, I am converting excel spreadsheets into CSV by saving CSV as excellence in CSV. But I'm not sure the client is doing this.
Then the TXT as a file is correct Ive checked the record and the total but now I have to convert it to CSV and I really want to do it in the program. Does anyone know how?
Here is my code:
Namespace editor CSV {class program {static without main (string [] arg) {ReadFromFile ("c: \\ source.csv" ); } Fixed Zero ReadFromFile (string filename) {StreamReader SR; Serial SW; SW = File.CreateText ("c: \\ target.csv"); String s; Four c = 'a'; Int i = 0; SR = File.OpenText (file name); S = SR.ReadLine (); SW.Write (s); S = SR.ReadLine (); While (s! = Null) {try {c = s [3]; } Hold (IndexOutRangeException exception) {bool t = false; While (t == wrong) {t = true; S = SR.ReadLine (); Try {C = S [3]; } Catch (IndexAxchange Exposure) {S = SR.ReadLine (); T = false; }}} If (C. Eulles (';')) {SW.Write ("\ r \ n" + S); I = i + 1; } And {SW.Write (S); } S = SR.ReadLine (); } SR.Close (); SW.Close (); Console.light line ("Records processed:" + i.ToString () + "."); Console WrightLine ("Fully Created File"); Console.ReadKey (); }}}}
CSV has predefined methods to handle this site's definition of standard Provides easy to read.
However, there is no reason not to use a solid, open source library to read and write the CSV files to prevent non-standard errors. This is my favorite library for it to support reading and writing in a clean and simple way.
Alternatively, you will be given a list of the most popular options.
Comments
Post a Comment