dimanche 25 janvier 2015

Simple issue writing from array to text file after storing what I have read as array and editing one of the arrays


Simple issue with writing back from array to text file after storing what I have read as array and editing one of the arrays. I need to write all the information back from the array into the text file.


I have read all the text and they are stored as variable[] called score in Results.


I want to write this back with new scores for one of the players.


I have the players name in a text box on my form


My text file consists of playername, lowscore highscore, blank space line inbetween Then three more players in this format.



scores = File.ReadAllLines(Source);
int counter = 0;
List<Score> Results = new List<Score>();
Score scor = new Score();
while (counter < scores.Length)
{
scor.Name = scores[counter];
scor.low = scores[counter +1];
scor.high = scores[counter + 2];
counter += 3;

}

List<string> NewScores = new List<string>();
foreach (Score score in Results)
{
NewScores.Add(score.Name);
NewScores.Add(score.low);
NewScores.Add(score.high);
NewScores.Add("");

}
File.WriteAllLines(Source, NewScores.ToArray());




Aucun commentaire:

Enregistrer un commentaire