从文本文件C#中删除文本 [英] deletion of text from text file c#

查看:88
本文介绍了从文本文件C#中删除文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我如何从文本文件(文本文件)中删除世界"之类的词
还包含许多其他文本,但仅搜索文本中输入的文本,然后按Web表单中创建的删除按钮将其删除....

any one can help me how to delete a word like "World" from a text file, the text file
contains a lot of more text also but only the text entered in a text is searched and then deleted by pressing a delete button created in a web form.......

推荐答案

1)将文本文件加载到内存中.
2)将文本从文本文件加载到变量中.
3)搜索世界"World"的变量.
4)将所有单词替换为空字符串.
5)将此字符串写回到文件中.
1) Load the text file into memory.
2) Load text from the text file into a variable.
3) Search for the varible for the world ''World''.
4) Replace all words with null strings.
5) Write this string back into the file.


您可以使用此代码语法
you can use this code Syntax
// FileName is your FileName and OldWord is Word which you want to delete
File.WriteAllText("FileName",File.ReadAllText("FileName").Replace("OldWord", "")); 


这篇关于从文本文件C#中删除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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