【问题标题】:C# separate the words in a text fileC# 分隔文本文件中的单词
【发布时间】:2017-03-21 00:17:14
【问题描述】:

我有一个文本文件,其中包含许多由; 分隔的单词。它看起来像这样:

eye;hand;mouth;arms;book
three;head;legs;home

我想浏览这个文件并搜索符号; 并修改文件,以便每个单词都用换行符转置。

我应该先读取字符串中的文本文件吗,

string path = @"c:\temp\MyTest.txt";
string readText = File.ReadAllText(path);

然后检查:

if readText.contains(";");

但我不知道下一步该做什么

【问题讨论】:

  • 使用 readText,Replace(";",Environment.NewLine)

标签: c# text-files


【解决方案1】:
string readText = File.ReadAllText(path);
var result = readText.Replace(";", Environment.NewLine);

【讨论】:

    【解决方案2】:

    使用

    readText.Replace(";",Environment.NewLine) 
    

    【讨论】:

      【解决方案3】:

      你是这个意思吗?

      string g = readText.Replace(";", "\n");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-30
        • 2016-09-16
        • 2014-07-29
        • 2015-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多