排序大型Unicode文本文件 [英] Sort large Unicode textfile

查看:108
本文介绍了排序大型Unicode文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设计一个实用程序,它可以对Unicode文本文件中的所有单词进行排序,并将结果输出到单独的文件中。单词由空格或新行分隔。我的文本文件非常大...有什么建议吗?

I would like to design a utility which sorts all words in a Unicode text file and output results into a separate file. Words are separated by spaces or new lines. My text file is very large... Any suggestions?

推荐答案

多大?

如果它是几兆字节,那么试试吧使用拆分和排序:

How large?
If it's a couple of megabytes, then try just using Split and Sort:
Stopwatch sw = new Stopwatch();
sw.Start();
string s = File.ReadAllText(@"D:\Temp\MyText.txt");
string[] data = s.Split(' ', '\n');
Array.Sort(data);
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);

1.6MB文本花费不到1.5秒,包括322,842个单词。

Took less than 1.5 seconds for 1.6MB of text, comprising 322,842 words.


这篇关于排序大型Unicode文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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