c# - StreamReader 行和行分隔符

标签 c# arrays tokenize delimiter streamreader

我正在尝试弄清楚如何标记文本文件的 StreamReader。我已经能够分隔行,但现在我试图弄清楚如何通过制表符分隔符来分解这些行。这就是我到目前为止所拥有的。

string readContents;
using (StreamReader streamReader = new StreamReader(@"File.txt"))
{
    readContents = streamReader.ReadToEnd();
    string[] lines = readContents.Split('\r');
    foreach (string s in lines)
    {
        Console.WriteLine(s);
    }
}
Console.ReadLine();

最佳答案

string readContents;
using (StreamReader streamReader = new StreamReader(@"File.txt"))
{
    readContents = streamReader.ReadToEnd();
    string[] lines = readContents.Split('\r');
    foreach (string s in lines)
    {
         string[] lines2 = s.Split('\t');
         foreach (string s2 in lines2)
         {
             Console.WriteLine(s2);
         }
    }
}
Console.ReadLine();

不太确定这是否是您想要的,但是...它会破坏(制表符)已经破坏的(返回)行

关于c# - StreamReader 行和行分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30200294/

相关文章:

Python word_tokenize 化

c# - 使用 Dispose() 或终结器来清理托管线程?

c - 在 C 编程中求两个长度不同的数组之和

java - 检查数组是否具有特定字符,为什么我的代码不起作用?

elasticsearch 自定义标记器 - 按长度拆分标记

python - 来自 Python 字符流的 Lisp 分词器

c# - Datagridview 填充行集?

c# - 调试混淆代码

c# - 检查多个键的多个值

java - 筛子定理数组中没有数字