Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2006

Tip: Looking for answers? Try searching our database.

replace string in file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stephanie Doherty - 22 Jun 2006 18:10 GMT
Hello World,

I am trying to replace a string in a large file without going through the
process of reading every line to locate the string in question. Is there a
function which will do this? I was looking into the FindReplace method of the
Find object, but couldn't find an example showing all the stuff that needs to
be added to the C++ code to use it.
In accordance with some sites on using DTE objects I've added the following
to my source file:

   #pragma warning( disable : 4278 )
   //The following #import imports DTE based on its LIBID
   #import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("7.0")
lcid("0") raw_interfaces_only named_guids
   #pragma warning( default : 4278 )
   using namespace EnvDTE; // optional

CComPtr<EnvDTE::_DTE> m_pDTE;
HRESULT hr = m_pDTE.CoCreateInstance("VisualStudio.DTE.7.1", 0, CLSCTX_ALL);

Find change;

change.FindReplace(vsFindAction.vsFindActionReplace,"<name>412<",NULL,"<Style>\n<iconstyle>\n<color>ff076aff</color>\n</iconstyle>\n</style>\n<name>412<",vsFindTarget.vsFindTargetFiles,KMLCounty,NULL,vsFindResultsLocation.vsFindResultsNone);

but when I try to compile the code I get errors like:

d:\data\dohertys\google earth\bridgedata\bridgedataDlg.cpp(180): error
C2039: 'vsFindResultsNone' : is not a member of 'System::Enum'
d:\data\dohertys\google earth\bridgedata\bridgedataDlg.cpp(170): error
C2259: 'EnvDTE::Find' : cannot instantiate abstract class
...

and lots of others

Does anyone have either some sample code to set this up, or an efficient
alternative?

Thanks,
Stephanie
Mihai N. - 23 Jun 2006 03:50 GMT
> I am trying to replace a string in a large file without going through the
> process of reading every line to locate the string in question. Is there a
> function which will do this?
This is not possible.
You might find a library or a function to do this, but that function or
library will do the reading, so if your problem is performance, then
there is not much you can do.
The only exception is if all lines are of equal length, if the line after
the replacement is also the same length, and you know a lot about the file
(for instance that is sorted).

DTE is part of the Visual Studio object model, so it is not available on
systems without Visual Studio installed. If you are writing a VS extension
this is fine, but otherwise ...

Signature

Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.