查找并替换文本文件中的字符串 [英] Find and replace a string in text file

查看:203
本文介绍了查找并替换文本文件中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个文本文件,现在我想在该文件中找到一个字符串,并且必须用其他字符串替换(只能在文本文件中找到并替换一个字符串).我正在尝试在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

推荐答案

成员4399771写道:
Member 4399771 wrote:

我正在尝试在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

  1. 在缓冲区(例如在CString对象中)读取文件(可能是部分读取)
  2. 在缓冲区中进行替换操作(CString具有方法)
  3. 再次使用CFile将修改后的缓冲区保存到磁盘.
  1. Read the file (maybe partially) in a buffer (for instance in a CString object)
  2. do the replace operations in the buffer (CString class has methods to do it)
  3. Save the modified buffer to disk using, again, CFile.


:)


这篇关于查找并替换文本文件中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆