sb
Nybegynder
01. marts 2004 - 17:35
Der er
3 kommentarer
Erstatte navn som findes fra før
Jeg har et array, myArray(100) som indeholder en række tekst-strenge. Et navn kan være maks 6 tegn langt. Jeg har brug for en algoritme som sørger for at samme streng ikke forekommer mere end 1 gang. Findes der dubletter skal disse ændres. Eks.: strengen "server" findes 12 gange. Disse forekomster skal da ændres til: server, serve1, serve2, serve3, ....., serv11
Annonceindlæg fra Infor
01. marts 2004 - 19:53
#2
Forudsætter at data ligger i alfabetisk rækkkefølge. //akj <% dim myarray(20) myarray(1) = "aaa" myarray(2) = "bbb" myarray(3) = "ccc" myarray(4) = "ccc" myarray(5) = "ccc" myarray(6) = "ddd" myarray(7) = "eee" myarray(8) = "fff" myarray(9) = "ggg" myarray(10) = "hhh" myarray(11) = "hhh" myarray(12) = "hhh" myarray(13) = "iii" myarray(14) = "jjj" myarray(15) = "jjj" myarray(16) = "kkk" myarray(17) = "lll" myarray(18) = "mmm" myarray(19) = "nnn" myarray(20) = "ooo" for i = 1 to ubound(myarray) response.write myarray(i) & "<br>" next for i = 1 to ubound(myarray) name = myarray(i) if name = lastname then c = c + 1 myarray(i) = left(myarray(i),len(myarray(i)) - len(c)) & c end if lastname=name next for i = 1 to ubound(myarray) response.write myarray(i) & "<br>" next %>
01. marts 2004 - 20:23
#3
Der gik lige lidt sport i det så her får du en der kan løse det selvom data ikke er sorteret //akj <% dim myarray(20) myarray(7) = "aaa" myarray(1) = "bbb" myarray(3) = "ccc" myarray(5) = "ccc" myarray(20) = "ccc" myarray(17) = "ddd" myarray(2) = "eee" myarray(4) = "fff" myarray(11) = "ggg" myarray(14) = "hhh" myarray(18) = "hhh" myarray(13) = "hhh" myarray(8) = "iii" myarray(10) = "jjj" myarray(12) = "jjj" myarray(19) = "kkk" myarray(6) = "lll" myarray(16) = "mmm" myarray(15) = "nnn" myarray(9) = "ooo" response.write "<hr>" response.write "Originale data" response.write "<hr>" for i = 1 to ubound(myarray) response.write myarray(i) & "<br>" next newarray = myarray for si = 1 to ubound(newarray) newarray = ArraySort(newarray) next response.write "<hr>" response.write "Originale data - sorteret" response.write "<hr>" for i = 1 to ubound(newarray) response.write newarray(i) & "<br>" next for i = 1 to ubound(newarray) name = newarray(i) if name = lastname then c = c + 1 newarray(i) = left(newarray(i),len(newarray(i)) - len(c)) & c ' newarray(i) = newarray(i) & c else c = 0 end if lastname=name next response.write "<hr>" response.write "Dupletter fjernet" response.write "<hr>" for i = 1 to ubound(newarray) response.write newarray(i) & "<br>" next Function ArraySort(temparray) For i = 0 To UBound(temparray)-1 For j = 1 To UBound(temparray)-i If temparray(i) > temparray(i+j) Then Temp = temparray(i) temparray(i) = temparray(i+j) temparray(i+j) = Temp Exit For End If Next Next ArraySort = temparray End Function %>