Article View: borland.public.cppbuilder.internet.web
Article #1223Re: How to replace text in a file
From: Hans Galema
Date: Mon, 05 Sep 2005 10:49
Date: Mon, 05 Sep 2005 10:49
32 lines
1671 bytes
1671 bytes
RS wrote:
> How to replace text in a .txt file ?
> for example :
> this is my "myfile.txt" :
>
> Hello "Jack",
>
> i would like replace the word Jack by John
>
> Hello "John"
Your problem has little to do with 'web'.
Replace "Jack" by "John":
AnsiString FileName = "mytext.txt";
TStringList *StringList = new TStringList;
StringList->LoadFromFile ( FileName );
StringList->Text = StringReplace ( StringList->Text
, "\"Jack\"", "\"John\""
, TReplaceFlags() << rfReplaceAll );
StringList->SaveToFile ( FileName );
delete StringList;
Hans.
Technical Details
Message-ID:
<431c228c$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!ecngs!feeder.ecngs.de!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<431ad5a0@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,214f73fbc3dc2fa6 X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 05 Sep 2005 12:49:26 +0200 From: Hans Galema <notused@notused.nl> User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.web Subject: Re: How to replace text in a file References: <431ad5a0@newsgroups.borland.com> In-Reply-To: <431ad5a0@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 129.125.201.248 Message-ID: <431c228c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1125917324 129.125.201.248 (5 Sep 2005 03:48:44 -0700) Lines: 32 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!ecngs!feeder.ecngs.de!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail