Click here to Skip to main content
15,887,322 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear friends,

I have problem with sorting in c# (window app). I need to get a file from a path for e.x

OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "*.txt|*.txt";

and then the words in this file to compare and to sort the words.
the file is data.txt

Cristiano Ronaldo
Lionel Messi
Van Persi
Steven Gerard
wayne rooney
Van Persi (duplicated)
Lionel Messi (duplicated)
Ect....

Nowm, I need to compare all of them and then to sort like that:

Cristiano Ronaldo
Lionel Messi
Lionel Messi
Steven Gerard
Van Persi
Van Persi
wayne rooney....


thank very much.
Best regards !
Posted
Comments
R. Giskard Reventlov 14-Apr-12 11:01am    
What have you tried for yourself? What researchhave you done? Anyway, sounds like home work and we don't do homework.

Since this is your previous question under another name, please give all the information!
You have the code to select a file (in your example above)
You have the code to read data from a file (in my previous answer)
You have the code to sort the data (in my previous answer)

All you don't have is the code to put the sorted data into a multiline Textbox, and frankly, that's not exactly rocket science:
C#
string[] lines = File.ReadAllLines(fileName);
...
myTextBox.Lines = lines;


So what is the problem? Just put all the bits together!
 
Share this answer
 
Comments
h7h7h7 14-Apr-12 12:33pm    
Dear friend, I don't have experience so much in c#...as I so you can help me.
I describe again the problem.
I have a text file in Desktop called data.txt with names and surnames. My problem is to read this file as you say "File.ReadAllLines(fileName);" and then to compare the data in file and to sort them...those name and surnime that are the same to collect together e.x
Besart Osmani
Besart Osmani
..
..
after sorting these word to put in a listbox...

I hope you understand what I need ... ! thankyou
OriginalGriff 14-Apr-12 12:38pm    
You have everything you need!
Do it one stage at a time, moving on only when it works:
1) Select the file. (It's only two or three lines of code!) When that works, move on.
2) Read the file (One line of code!)
3) Sort the data (one line again)
4) Output the sorted data to teh textbox (One more line!)

If I give you any more I will have done your homework for you...:laugh:
Try it: if you can't get the first stage working, post your code, and I'll point out the problem - but I don't think I should write your whole submission for you!
h7h7h7 14-Apr-12 12:47pm    
haha thankyou man, I think I have solved the problem with your help...
I think latter I should Ask you something else...... please can you write me in besartosmani1@gmail.com I will sent you my code...!
thank you
OriginalGriff 14-Apr-12 14:16pm    
Sorry, but no!
If you need more help, post another question here - I (or someone like me) will read it. :)
Look at some solutions here[^] and here[^].
 
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