programmatically replace characters in a text file?

C

cheesywillie

How would this be done? For example find every "a" and replace them
with a "b".

Sorry if i am not being descriptive enough, but i don't know how else
to phrase the question. If you need any additional information just
ask.

Thanks for reading.
 
V

Victor Bazarov

How would this be done? For example find every "a" and replace them
with a "b".

Sorry if i am not being descriptive enough, but i don't know how else
to phrase the question. If you need any additional information just
ask.

Open the file for both read and write
While the file is OK
Read some bytes from the file into a buffer
Replace chars in the buffer as needed
Position the file pointer back
Write the buffer back into the file
End-while

V
 
J

James Kanze

How would this be done? For example find every "a" and replace them
with a "b".

std::replace_copy( std::istreambuf_iterator< char >( source ),
std::istreambuf_iterator< char >(),
std::eek:streambuf_iterator< char >( dest ),
'a',
'b' ) ;
 
A

AnonMail2005

How would this be done? For example find every "a" and replace them
with a "b".

Sorry if i am not being descriptive enough, but i don't know how else
to phrase the question. If you need any additional information just
ask.

Thanks for reading.
Depending on what system you are on, there are utilities that can
do this w/o any programming. For instance, check out the unix
utility tr.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top