[ASP ]Duplicaten deleten uit een array

Pagina: 1
Acties:

  • MankE NeliZ
  • Registratie: Mei 2000
  • Laatst online: 23-07 06:49

MankE NeliZ

Geen matches

Topicstarter
Ik heb er een functie voor gevonden (RemDups) maar dat werkt niet...heeft iemand een idee waar het aan ligt/een oplossing voor mijn probleem?

Het enige wat ik wil doen is bijv:

string 1 = oud (1, 2, 5, 33)
string 2 = toevoeging (2, 10, 33, 88)
string 3 = string 1 + 2 (1, 2, 5, 33, 2, 10, 33, 88) (NewMoviesList)

string >convert> array

Wat ik dus wil is dat de dupes 2, 5 en 33 uit de array verwijderd worden.

Dit is de code:



If Not CurrentMovieList ="" Then ' USER HAS ONE OR MORE MOVIE

'Display Movielist of current user

response.write "<br><br>Current movies " & CurrentMovieList
response.write "<br><br>Added movies " & MoviesToAdd
NewMoviesList = CurrentMovieList &", "& MoviesToAdd
response.write "<br><br>New movies " & NewMoviesList &"<br><br>"
'response.end

Else ' USER HAS NO MOVIES

'Display Movielist of current user

response.write "yep<br><br>Added movies " & MoviesToAdd
NewMoviesList=MoviesToAdd

End if

'NOW DELETE DUPLICATES

function RemDups(byVal anArray)
dim d, item, thekeys
set d = CreateObject("Scripting.Dictionary")
d.removeall
d.CompareMode = 0
for each item in anArray
if not d.Exists(item) then d.Add item, item
next
thekeys = d.keys
set d = nothing
RemDups = thekeys
end function

function ShowArray(byval arr)
dim item, s
for each item in arr
s = s & item & "<BR>"
next
ShowArray = s
end function

theArray = split(NewMoviesList,",") 'hier converteert hij de string naar een array
response.write " " &isArray(theArray)&"<br><br>" ' return true - het is dus een array
' show the array with duplicate values
response.write "show filtered array<br><br>before:<br><br>" & showArray(theArray)
' remove duplicate numbers
theArray = RemDups(theArray)
' show the array with no duplicate values
response.write "<br>after:<br><br>" & showArray(theArray)

End if

response.write"</p>"

End if

In Kazachstan we say a woman with a book...is like a horse...with wings!


  • Gert
  • Registratie: Juni 1999
  • Laatst online: 05-12-2025
Je stopt er items in en stopt daarna de keys in de array?

  • Apache
  • Registratie: Juli 2000
  • Laatst online: 02-09 12:24

Apache

amateur software devver

een zoek functie schrijven en telkens als het niet gevonden is bijvoegen en sorteren?

If it ain't broken it doesn't have enough features


  • MankE NeliZ
  • Registratie: Mei 2000
  • Laatst online: 23-07 06:49

MankE NeliZ

Geen matches

Topicstarter
Een zoekfunctie....interessant...daar had ik nog niet aan gedacht.

Thanx!

In Kazachstan we say a woman with a book...is like a horse...with wings!