Text File Manipulation

  • Thread starter Thread starter Garth Wells
  • Start date Start date
G

Garth Wells

I need to open up a .csv and replace all adjacent commas
(,,) with comma zero comma (,0,). Anybody have an
example of how to do this?

Thanks
 
3 steps:
Read the entire content of the file into string
Replace all occurrences of ",," with ",0,"
Write the string to a new file or overwite the existing file

Check out the documentation for the StreamReader class. You will find a
range of examples, combinations of which will help you out.
 
Garth Wells said:
I need to open up a .csv and replace all adjacent commas
(,,) with comma zero comma (,0,). Anybody have an
example of how to do this?


'System.IO.StreamReader', 'System.IO.StreamWriter', 'String.Replace',
'Strings.Replace'.
 
I need to open up a .csv and replace all adjacent commas
(,,) with comma zero comma (,0,). Anybody have an
example of how to do this?

If you're doing it on a per line basis, I would open the file using
System.IO and reach each line. Then use String.Replace to replace all
adjacent commas.

Once the line is fixed, use StringBuilder to re-concatentate all the lines
together (don't use string concatenation (i.e. String A + String B) if you
have more than 10 - 20 lines, string concatenation slows down exponentially
- it gets REALLY slow for large files).
 
No VB.NET required for this.

Open the file with Notepad
Click Edit, Click Replace
In the "Find What" box type in ",,"
In the "Replace With" box type in ",0,"
Click Replace All
Save Document
You're done!

If this operation has to be done over and over again, then use VB.NET
as others have described.
 
Touche'

Izzy said:
No VB.NET required for this.

Open the file with Notepad
Click Edit, Click Replace
In the "Find What" box type in ",,"
In the "Replace With" box type in ",0,"
Click Replace All
Save Document
You're done!

If this operation has to be done over and over again, then use VB.NET
as others have described.
 
Back
Top