Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

xanburzum

[Resolvido] Removendo itens duplicados

Recommended Posts

Removendo itens duplicados a partir de uma matriz e retorna um novo array sem duplicatas.

 

sintaxe:

 

array = RemoveDup(array
)

 

exemplo:

 

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

dim theArray

 ' #############################################
 ' # criar um teste com um array.......  #
 ' #############################################

theArray = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0,_
		 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,_
		 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,_
		 1, 2, 3, 4, 5, 6, 7, 8, 9, 0,_
		 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)

 ' mostrar array antes modificações
response.write "Antes:<HR>" & showArray (theArray) & "</HR>"

 ' remover números duplicados 
theArray = RemoveDup(theArray)

 ' mostrar o array sem valores duplicados
response.write "Depois:<HR>" & showArray (theArray) & "</HR>"

 ' #############################################
 ' # criar um teste com uma string array.......  #
 ' #############################################

xArray = Array("ox", "xan", "jeff", "ri", _
		 "lika", "lucia", "romao", _
		 "lika", "gu", "burzum", "pig", _
		 "xan", "romao", "jeff", _
		 "ri", "andy")

 ' mostrar array antes modificações
response.write "Antes:<HR>" & showArray (xArray) & "</HR>"

 ' remover string valores duplicados
xArray = RemoveDup(xArray)

 ' mostrar o array sem valores duplicados
response.write "Depois:<HR>" & showArray (xArray) & "</HR>"
%>

code:

<%
function RemoveDup(byVal anArray)
	dim d, item, keys

	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
	keys = d.keys
	set d = nothing
	RemoveDup= keys
end function
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.