I’m going to make a scoreboard for an XNA game but I’m having some trouble figuring out how. The player, after finishing a level, will enter his name when prompted. His name and time will be recorder in a text file something like this:
sam 90
james 64
matthew 100
I’m trying to figure out a way to sort this data by the time taken only and not taking into account the name.
I haven’t started coding this yet but if anybody can give me any ideas it would be greatly appreciated.
First, read the text file using
File.ReadAllLines(...)so you get a string array. Then iterate over the array and split each string on blank space (assuming users can’t enter spaces in their names) and order on the second element, which should be the score. You have to cast it into a string withint.Parse(...)to be able to order it properly.I would recommend using something like a semi-colon to separate the name and the score instead of a space, as that makes it much easier to handle in the case that users are allowed to enter spaces in their names.