I am currently working on a project and have hit a snag.
I'm taking in an unformatted string[]
of football teams and I'm trying to filter the data and return it in a more orgainised format.
I'm fine with most of it (splitting the string to get the relevant values and sorting the format) except i have created a Team object which holds most of this data and as i loop through the original string i create a new team object each time i see a team name. Then i check to see if i've seen that object before and if i have i don't create a new object. After creating the Team or skipping that part i add the relevant info to the team object and continue.
My issue is the list i'm using to hold the final team info has many duplicates mean my check to see if the object exists or not doesn't work. The code is :
After splitting string,
List<Team> teams = new List<Team>();
for (int i = 1; i <= matches.Length - 1; i++)
{
string fullStr = matches[i];
string[] score = fullStr.Split(',');
string[] team1 = score[0].Split('!');
string team1Name = team1[0];
Team teams1 = new Team(team1Name);
if (teams.Contains(teams1) != true)
{
teams.Add(teams1);
}
string team1Score = team1[1];
int team1ScoreInt = int.Parse(team1Score);
string[] team2 = scores[1].Split('!');
string team2Name = team2[1];
Team teams2 = new Team(team2Name);
if (!teams.Contains(teams2))
{
teams.Add(teams2);
}
When i print the list i get the format i want but multiple Germanys etc. And only the score etc of that 1 game rather than them all adding to 1 Germany Team object.
Any ideas how i can stop the duplicates and maintain using only the 1 Team object every time i see that team name?
Thanks