句子与StreamReader txt对齐到txt吗? [英] Sentences to line with StreamReader txt to txt ?

查看:87
本文介绍了句子与StreamReader txt对齐到txt吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读c.txt
只将不同的值写入21.txt
没关系
但我看不懂它的句子,它只能读一行:(
c.txt有语句,所以我想读单词word来写21.txt行line :).

read c.txt
write only different values to 21.txt
its ok
but I cant read sentece it only read line :(
c.txt have senteces so I want to read word word to write 21.txt line line :).

static void Main(string[] args)
        {
            string d = @"C:\C.txt";
            FileStream f = new FileStream(d,FileMode.Open);            
            StreamReader s = new StreamReader(f);

            string d2 = @"C:\21.txt";
            FileStream f2 = new FileStream(d2,FileMode.Create, FileAccess.Write);
            StreamWriter s2 = new StreamWriter(f2);


            ArrayList lst = new ArrayList();
            
            
            string line;
            while ((line = s.ReadLine()) != null)
            {                
                if(!lst.Contains(line)){
                lst.Add(line);
                }              
            }
            
            foreach(Object lstt in lst){
              
                //Console.WriteLine(lstt);
                s2.WriteLine(lstt);
            }


            s2.Flush();
            s2.Close();
            s.Close();
            Console.ReadLine();

        }

推荐答案

嗨!
您可以使用String.Split方法从文件中读取所有文本并将其拆分为句子.像这样:
hi!
you can read all text from the file and split it to sentences using String.Split method. like this:
foreach(string sentence in System.IO.File.ReadAllText(d).Split(new char[]{'.',',','!','?',';'})
            {
                if (!lst.Contains(sentence ))
                {
                    lst.Add(sentence );
                }
            }



添加了 [edit]代码标签[/edit]



[edit] code tags added[/edit]


这篇关于句子与StreamReader txt对齐到txt吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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