查找并替换文本文件中的字符串 [英] Find and replace a string in text file
问题描述
大家好,
我有一个文本文件,现在我想在该文件中找到一个字符串,并且必须用其他字符串替换(只能在文本文件中找到并替换一个字符串).我正在尝试在MFC中使用CFile类,但是执行此类操作的方法有限.任何机构都可以提出一些想法来完成此任务,或者如果您有任何这样的应用程序,请给我参考.
提前谢谢.
问候,
anil
Hi all,
I have one text file, now I want to find a string in that file and have to replace with some other string(nothing but find and replace a string in text file). I am trying to use CFile class in MFC, but it has limited methods to do such operations. can any body give some idea to accomplish this or if you have any such application please send me for reference.
Thanks in advance.
Regards,
anil
推荐答案
我正在尝试在MFC,但执行此类操作的方法有限.
I am trying to use CFile class in MFC, but it has limited methods to do such operations.
CFile应该提供文件处理(打开,关闭,读取,写入)方法.你必须
CFile provides file handling (open, close, read, write) methods, as it should. You have to
- 在缓冲区(例如在
CString
对象中)读取文件(可能是部分读取) - 在缓冲区中进行替换操作(
CString
类具有方法) - 再次使用
CFile
将修改后的缓冲区保存到磁盘.
- Read the file (maybe partially) in a buffer (for instance in a
CString
object) - do the replace operations in the buffer (
CString
class has methods to do it) - Save the modified buffer to disk using, again,
CFile
.
:)
这篇关于查找并替换文本文件中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!