|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Text File ManipulationI 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. Show quoteHide quote "Garth Wells" <nob***@nowhere.com> wrote in message news:bACTg.3620$DU3.1968@tornado.texas.rr.com... >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 > MyString=MyString.Replace(",,",",0,")
Show quoteHide quote "Garth Wells" <nob***@nowhere.com> wrote in message news:bACTg.3620$DU3.1968@tornado.texas.rr.com... >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 > "Garth Wells" <nob***@nowhere.com> schrieb: 'System.IO.StreamReader', 'System.IO.StreamWriter', 'String.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? 'Strings.Replace'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> "Garth Wells" <nob***@nowhere.com> wrote in news:bACTg.3620$DU3.1968 @tornado.texas.rr.com:> I need to open up a .csv and replace all adjacent commas If you're doing it on a per line basis, I would open the file using > (,,) with comma zero comma (,0,). Anybody have an > example of how to do this? 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. Garth Wells wrote: Show quoteHide quote > 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 Touche'
Show quoteHide quote "Izzy" <israel.rich***@gmail.com> wrote in message news:1159737029.780520.189350@h48g2000cwc.googlegroups.com... > 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. > > > Garth Wells wrote: >> 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 > |
|||||||||||||||||||||||