Hi,
can you help me to remove an element in my dictionary ?
Code for create dictionary :
Divisions = New Dictionary
Dim ALEast() As Text = Array("Red Sox", "Yankees", "Rays", "Orioles", "Blue Jays")
Dim ALCentral() As Text = Array("Tigers", "White Sox", "Twins", "Royals", "Indians")
Dim ALWest() As Text = Array("Angels", "Mariners", "Rangers", "Athletics", "Astros")
Dim NLEast() As Text = Array("Mets", "Braves", "Nationals", "Marlins", "Phillies")
Dim NLCentral() As Text = Array("Cardinals", "Brewers", "Reds", "Pirates", "Cubs")
Dim NLWest() As Text = Array("Dodgers", "Pardres", "Giants", "Diamondbacks", "Rockies")
Divisions.Value("AL East") = ALEast
Divisions.Value("AL Central") = ALCentral
Divisions.Value("AL West") = ALWest
Divisions.Value("NL East") = NLEast
Divisions.Value("NL Central") = NLCentral
Divisions.Value("NL West") = NLWest
I would like to remove by code the “Red Sox” team from division “ALEast”.
[quote]Value(key As Auto, Assigns newValue As Auto)
Adds a new key-value pair to the Dictionary. If there is already an entry with the specified key, its value is altered and no exception is raised.[/quote]
Dim ALEast() As Text = Array("Yankees", "Rays", "Orioles", "Blue Jays")
Divisions.Value("AL East") = ALEast
If I understood correctly, Jrme asked for removing one entry of the values.
Should be something like
Dim Entries() As Text = Divisions.Value("AL East")
Dim Pos As Integer = Entries.IndexOf ("Red Sox")
If Pos > -1 then
Entries.Remove(pos)
Divisions.Value("AL East") = Entries
End If
[quote=282706:@Ulrich Bogun]If I understood correctly, Jérôme asked for removing one entry of the values.
Should be something like
Dim Entries() As Text = Divisions.Value("AL East")
Dim Pos As Integer = Entries.IndexOf ("Red Sox")
If Pos > -1 then
Entries.Remove(pos)
Divisions.Value("AL East") = Entries
End If[/quote]
Thank you @UlrichBogun , my “solution” was assuming it’s already known in which Key the Red Sox will be in and used a quick and dirty replacement for this Key. Your solution is by far better.