Hi. I'm trying to sort my list of strings by a #'s that occur near the end of the string.
Example:
PLAYER_NAME: Temp PLAYER_SCORE: 1
PLAYER_NAME: Temp PLAYER_SCORE: 7
PLAYER_NAME: Temp PLAYER_SCORE: 4
Now I want it to appear like this on my output:
Name: Temp Score: 7
Name: Temp Score: 4
Name: Temp Score: 1
I have it outputting properly expect its not sorting my Score.
Here is my current code:
Note, I'm using XNA 3.1 but this is WinForm Code for Reading and Sorting.
Code:string line; string leaderName = string.Empty; string leaderScore = string.Empty; int lastScore = 0; int currentScore = 0; List<string> Leaderboard = new List<string>(); UIYourScore = new UIClass(); UIYourScore.FontType = Game.Content.Load<SpriteFont>(@"UIScoreFont"); UIYourScore.Value = Player.Score; UIYourScore.String = "Your Score: " + UIYourScore.Value.ToString(); UIYourScore.Position = new Vector2(250, 150); UIBestScore = new UIClass(); UIBestScore.FontType = Game.Content.Load<SpriteFont>(@"UIScoreFOnt"); File.AppendAllText(StorageContainer.TitleLocation + @"\Leaderboard.txt", "PLAYER_NAME: Temp" + Environment.NewLine + "PLAYER_SCORE: " + Player.Score.ToString() + Environment.NewLine); TextReader tr = new StreamReader(StorageContainer.TitleLocation + @"\Leaderboard.txt"); while ((line = tr.ReadLine()) != null) { if (line.Contains("PLAYER_NAME: ")) { line = line.Remove(0, 13); leaderName = line; } if (line.Contains("PLAYER_SCORE: ")) { line = line.Remove(0, 14); lastScore = int.Parse(line); leaderScore = lastScore.ToString(); if (currentScore <= lastScore) { currentScore = lastScore; UIBestScore.Value = currentScore; } Leaderboard.Add("Name: " + leaderName + "\t Score: " + leaderScore); } } tr.Close(); UIBestScore.String = "Best Score: " + UIBestScore.Value.ToString(); UIBestScore.Position = new Vector2(250, 175); UILeaderboard = new UIClass[Leaderboard.Count - 1]; for (int i = 0; i < Leaderboard.Count - 1; i++) { UILeaderboard[i] = new UIClass(); UILeaderboard[i].FontType = Game.Content.Load<SpriteFont>(@"UIScoreFont"); UILeaderboard[i].String = Leaderboard[i] + Environment.NewLine; if (i == 0) UILeaderboard[i].Position = new Vector2(800, 150); else UILeaderboard[i].Position = new Vector2(800, UILeaderboard[i - 1].Position.Y + 20); }




Reply With Quote