【问题标题】:Deleting particular text in a file using c#?使用c#删除文件中的特定文本?
【发布时间】:2010-07-21 10:47:16
【问题描述】:

我的名为 test.txt 的文本文件包含

修复元素签入期间的类型管理器错误以及签入/签出和合并相关问题期间的支持问题。

现在我想使用 c# 删除文本“支持问题”。

请任何人告诉我。

提前致谢, Naveenkumar.T

【问题讨论】:

  • 您到底在问什么?如何打开文件?如何解析文件?如何处理数据?至少,我们需要查看所述文本文件的格式。这并不难,但确实需要更多信息。
  • 我想他描述的很清楚——他有一个文本文件,内容显示在问题中,他想从中删除两个词..?
  • @Kieren Johnstone:是的,它已经重新格式化,现在更加清晰。当我发表评论时,对我来说还不是很清楚。

标签: c# file string


【解决方案1】:

如果文件很小,你可以这样做:

using System.IO; // at the top of the file

string file = "path.txt"; // change to the path

// read the whole file into a string, make a replacement, then write all string to a file
File.WriteAllText(file, File.ReadAllText(file).Replace("supporting issues ",""));

希望对您有所帮助。

【讨论】:

  • 哈哈很好,这教会了我们过多地阅读问题。不错!
猜你喜欢
  • 1970-01-01
  • 2022-12-13
  • 1970-01-01
  • 1970-01-01
  • 2020-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多