|
-
Sep 27th, 2009, 08:35 PM
#1
Thread Starter
Lively Member
How to remove a last character from a csv file ?
Hello,
I was wondering if anyone could help me with the following problem:
I am working with a csv file (it contains two columns of numbers), which as a last character has a comma and I would like to remove that comma from the file.
Could ayone show me a code that might do it ?
THANKS!
-
Sep 27th, 2009, 08:42 PM
#2
Re: How to remove a last character from a csv file ?
Does every line end with a comma, or just the last one.
Either way you will need to use something like ReadAllLines to bring the whole file into memory, then manipulate, then write, but it depends a bit on what actually needs to be removed.
My usual boring signature: Nothing
 
-
Sep 27th, 2009, 08:44 PM
#3
Thread Starter
Lively Member
Re: How to remove a last character from a csv file ?
Hi SH !
No, only the last line has a comma. Can I just read the last character and if it si a comma then remove it ?
Thanks!
-
Sep 27th, 2009, 09:05 PM
#4
Re: How to remove a last character from a csv file ?
I don't think you can really do that. One way or another, the entire file will pass into memory and back out again. ReadAllLines would certainly do, as it would create an array of text lines, and you would only need to look at the last string in the array. In some ways, this may be the most straightforward solution, but I'd certainly look into a different option, as well. Unfortunately, I have never tried this:
A memory stream would allow you to see the bytes, and you could then look at the last few. I would think that a streamreader might give you the same means. On the other hand, that last line might have some hidden characters (a carriage return and line feed pair) after the comma, so this may prove to be more trouble than its worth.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|