Fjern forekomster i streng
HejJeg har følgende side: http://www.selvet.dk/exp.asp
På den side skal et script undersøge en streng af datoer. Den skal fjerne datoen "03-05-2003", fordi det er den dato, som forekommer to gange (eller derover).
Men det gør den ikke, se resultatet ved at klikke på linket.
_______________KODEN FRA SIDEN____________________
<%
Set myConn=Server.CreateObject("ADODB.Connection")
myConn.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="+server.Mappath("/db/selvet.mdb"))
strSQL = "SELECT datopublish FROM search WHERE datopublish >= #" & Year(date) & "-" & month(date) & "-" & Day(date) & "# AND datopublish < #" & Year(dateadd("yyyy",1,date)) & "-" & month(dateadd("yyyy",1,date)) & "-" & Day(dateadd("yyyy",1,date)) & "# order by datopublish"
set rs = myConn.execute(strSQL)
do while not rs.EOF
if isDate(rs("datopublish")) then
myDates = myDates & rs("datopublish") & ", "
End If
rs.MoveNext
Loop
if right(myDates, 2) = ", " then
myDates = left(myDates,len(myDates)-2)
end if
response.write "<br>Skal undersøge: <br>" & myDates & "<br><br><br>"
response.write "<br>Finder (fejlagtigt): <br>"
myDateArr = Split(myDates,",")
dato = date ()
datoSlut = DateAdd("yyyy",1,date)
i = 0
do while dato <= datoSlut
if countDates(myDateArr(i), myDates) < 2 and CDate(myDateArr(i)) <> CDate(dato) then
response.write myDateArr(i) & ", "
else
i = i + 1
if i > ubound(myDateArr) then i = ubound(myDateArr)
end if
dato = dateAdd("d",1,dato)
loop
response.write "<br><br>Hvis det var rigtigt, havde den fundet:<br> 18-03-2003, 19-03-2003, 20-03-2003, 21-03-2003, 22-03-2003, 23-03-2003, 24-03-2003, 25-03-2003, 26-03-2003, 27-03-2003, 28-03-2003, 29-03-2003, 30-03-2003, 31-03-2003, 01-04-2003, 02-04-2003, 03-04-2003, 04-04-2003, 05-04-2003, 06-04-2003, 07-04-2003, 08-04-2003, 09-04-2003, 10-04-2003, 11-04-2003, 12-04-2003, 13-04-2003, 14-04-2003, 15-04-2003, 16-04-2003, 17-04-2003, 18-04-2003, 19-04-2003, 20-04-2003, 21-04-2003, 22-04-2003, 23-04-2003, 24-04-2003, 25-04-2003, 26-04-2003, 27-04-2003, 28-04-2003, 29-04-2003, 30-04-2003, 02-05-2003, 04-05-2003, 05-05-2003, 06-05-2003, 08-05-2003, 09-05-2003, 15-05-2003, 19-05-2003, 26-05-2003, 27-05-2003, 01-06-2003, 06-06-2003, 07-06-2003, 26-06-2003, 18-08-2003, 31-08-2003, 05-09-2003"
response.write "<br><br>Det skulle bare være de værdier, som forekom to gange eller derover... i dette tilfælde: 03-05-2003, 03-05-2003 der var blevet fjernet fra ovenstående liste af datoer."
Function countDates(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search.
For Each Match in Matches ' Iterate Matches collection.
intMatchCount = intMatchCount + 1
Next
countDates = intMatchCount
End Function
%>