Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
Posted

1 solution

How large?
If it's a couple of megabytes, then try just using Split and Sort:
C#
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);
Took less than 1.5 seconds for 1.6MB of text, comprising 322,842 words.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900