Avatar billede mortency Nybegynder
30. oktober 2003 - 13:33 Der er 17 kommentarer og
1 løsning

Replace mellomrom

innholdet i q er= "asp er bra"

Request.QueryString("q")

Ny q skal bli: asp,er,bra
Avatar billede keysersoze Ekspert
30. oktober 2003 - 13:35 #1
replace(Request.QueryString("q")," ",",")
Avatar billede cool_casper Nybegynder
30. oktober 2003 - 13:35 #2
Response.Write Replace(Request.QueryString("q")," ",",")
Avatar billede cool_casper Nybegynder
30. oktober 2003 - 13:35 #3
baah, 5 sekunder for sent! ;)
Avatar billede mortency Nybegynder
30. oktober 2003 - 13:40 #4
Vet dere også hvordan jeg får dette til å bli en function? Så jeg kan kalle den opp på flere input data?

    Dim strSearchWithin,strSearchFor
    strSearchWithin = adoRs("DocContent")
    strSearchFor= replace(Request.QueryString("q")," ",",")

    dim strAr,j,pos,FndPos,str,newstr
    strAr = split(strSearchFor, ",")

    For j = 0 To UBound(strAr)
        strAr(j) = trim(strAr(j))
    next
    pos = 1
    FndPos = 1
    For j = 0 To UBound(strAr)
        FndPos = instr(1, strSearchWithin, strAr(j),1)
        Do While FndPos<>0
            str = Mid(strSearchWithin, 1, (FndPos-1)+len(strAr(j)))
            newstr = Mid(str, 1, FndPos - 1) & "<B><i>" & Mid(str, FndPos, len(strAr(j))) & "</i></B>"
            strSearchWithin = replace(strSearchWithin, str, newstr)
            pos = FndPos+len(strAr(j)) + 3
            FndPos = instr(pos, strSearchWithin, strAr(j),1)
        Loop
    next
Avatar billede keysersoze Ekspert
30. oktober 2003 - 13:43 #5
Function replaceme(VAR)
  replaceme = replace(VAR, " ", ",")
End Function

kaldes sådan

replaceme(Request.QueryString("q"))
Avatar billede mortency Nybegynder
30. oktober 2003 - 13:47 #6
//Keysersoze

Jeg mener denne.

  Dim strSearchWithin,strSearchFor
    strSearchWithin = adoRs("DocContent")
    strSearchFor= replace(Request.QueryString("q")," ",",")

    dim strAr,j,pos,FndPos,str,newstr
    strAr = split(strSearchFor, ",")

    For j = 0 To UBound(strAr)
        strAr(j) = trim(strAr(j))
    next
    pos = 1
    FndPos = 1
    For j = 0 To UBound(strAr)
        FndPos = instr(1, strSearchWithin, strAr(j),1)
        Do While FndPos<>0
            str = Mid(strSearchWithin, 1, (FndPos-1)+len(strAr(j)))
            newstr = Mid(str, 1, FndPos - 1) & "<B><i>" & Mid(str, FndPos, len(strAr(j))) & "</i></B>"
            strSearchWithin = replace(strSearchWithin, str, newstr)
            pos = FndPos+len(strAr(j)) + 3
            FndPos = instr(pos, strSearchWithin, strAr(j),1)
        Loop
    next
Avatar billede keysersoze Ekspert
30. oktober 2003 - 13:48 #7
ikke helt med?
Avatar billede mortency Nybegynder
30. oktober 2003 - 13:54 #8
//Keysersoze

Prøver å forklare.

Jeg henter ut data fra en database, feltene er adoRs("DocTitle") og adoRs("DocContent")

Med overstående kode så higlighter jeg dataene som jeg søker på.

Hvordan får jeg gjort om det til en funksjon som kan highlighte forskjellige data?

Function Highlight(VAR)
  Dim strSearchWithin,strSearchFor
    strSearchWithin = adoRs("DocContent")
    strSearchFor= replace(Request.QueryString("q")," ",",")

    dim strAr,j,pos,FndPos,str,newstr
    strAr = split(strSearchFor, ",")

    For j = 0 To UBound(strAr)
        strAr(j) = trim(strAr(j))
    next
    pos = 1
    FndPos = 1
    For j = 0 To UBound(strAr)
        FndPos = instr(1, strSearchWithin, strAr(j),1)
        Do While FndPos<>0
            str = Mid(strSearchWithin, 1, (FndPos-1)+len(strAr(j)))
            newstr = Mid(str, 1, FndPos - 1) & "<B><i>" & Mid(str, FndPos, len(strAr(j))) & "</i></B>"
            strSearchWithin = replace(strSearchWithin, str, newstr)
            pos = FndPos+len(strAr(j)) + 3
            FndPos = instr(pos, strSearchWithin, strAr(j),1)
        Loop
    next
End Function

highlight(adoRs("DocTitle"))
highlight(adoRs("DocContent"))
Avatar billede keysersoze Ekspert
30. oktober 2003 - 14:06 #9
kan du give et eksempel på hvad du mener?
Avatar billede mortency Nybegynder
30. oktober 2003 - 14:14 #10
Se hele koden:

<%
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdText = &H0001
Const adUseClient = 3

Dim currentPage
If Len(Request.QueryString("currentPage")) = 0 Then
    currentPage = 1
Else
    currentPage = CInt(Request.QueryString("currentPage"))
End If

Dim recordsToShow
recordsToShow = 5
                           
Dim strKeyword
strKeyword = split(Trim(Request.QueryString("q")), " ")
                           
Set adoRs = CreateObject("ADODB.Recordset")
adoRs.CursorLocation = adUseClient
adoRs.PageSize = recordsToShow
adoRs.CacheSize = recordsToShow

'-------------------------------------
'SØKER I DOKUMENTER START   
'-------------------------------------
Set adoRs = CreateObject("ADODB.Recordset")
adoRs.CursorLocation = adUseClient
adoRs.PageSize = recordsToShow
adoRs.CacheSize = recordsToShow
               
Select Case UBound(strKeyword)
    Case 0     adoRs.Open "SELECT DocID, DocMenuTitle,DocLink,DocLinkUrl,DocLinkTarget,DocTitle,DocContent,DocCreated FROM tblWPDocuments Where DocMenuTitle LIKE '%" & strKeyword(0) & "%' OR DocTitle LIKE '%" & strKeyword(0) & "%' OR DocContent LIKE '%" & strKeyword(0) & "%' ORDER BY DocCreated DESC", adoCn, adOpenForwardOnly, adLockReadOnly, adCmdText
    Case 1        adoRs.Open "SELECT DocID, DocMenuTitle,DocLink,DocLinkUrl,DocLinkTarget,DocTitle,DocContent,DocCreated FROM tblWPDocuments Where DocMenuTitle LIKE '%" & strKeyword(0) & "%' OR DocMenuTitle LIKE '%" & strKeyword(1) & "%' OR DocTitle LIKE '%" & strKeyword(0) & "%' OR DocTitle LIKE '%" & strKeyword(1) & "%' OR DocContent LIKE '%" & strKeyword(0) & "%' OR DocContent LIKE '%" & strKeyword(1) & "%' ORDER BY DocCreated DESC", adoCn
    Case 2        adoRs.Open "SELECT DocID, DocMenuTitle,DocLink,DocLinkUrl,DocLinkTarget,DocTitle,DocContent,DocCreated FROM tblWPDocuments Where DocMenuTitle LIKE '%" & strKeyword(0) & "%' OR DocMenuTitle LIKE '%" & strKeyword(1) & "%' OR DocMenuTitle LIKE '%" & strKeyword(2) & "%' OR DocTitle LIKE '%" & strKeyword(0) & "%' OR DocTitle LIKE '%" & strKeyword(1) & "%' OR DocTitle LIKE '%" & strKeyword(2) & "%' OR DocContent LIKE '%" & strKeyword(0) & "%' OR DocContent LIKE '%" & strKeyword(1) & "%' OR DocContent LIKE '%" & strKeyword(2) & "%' ORDER BY DocCreated DESC", adoCn
    Case Else    adoRs.Open "SELECT DocID, DocMenuTitle,DocLink,DocLinkUrl,DocLinkTarget,DocTitle,DocContent,DocCreated FROM tblWPDocuments Where DocMenuTitle LIKE '%" & strKeyword(0) & "%' OR DocMenuTitle LIKE '%" & strKeyword(1) & "%' OR DocMenuTitle LIKE '%" & strKeyword(2) & "%' OR DocTitle LIKE '%" & strKeyword(0) & "%' OR DocTitle LIKE '%" & strKeyword(1) & "%' OR DocTitle LIKE '%" & strKeyword(2) & "%' OR DocContent LIKE '%" & strKeyword(0) & "%' OR DocContent LIKE '%" & strKeyword(1) & "%' OR DocContent LIKE '%" & strKeyword(2) & "%' ORDER BY DocCreated DESC", adoCn
    End Select

%>
<table width="601" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="601" height="<%=strHeight%>"></td>
  </tr>
  <tr>
    <td class="heading" width="601" height="15"><font color="#<%=strTMouseover%>">Søk i Dokumenter</font></td>
  </tr>
</table>
<%

If Not adoRs.EOF Then

Dim totalpages
totalpages = adoRs.PageCount
adoRs.AbsolutePage = currentPage

Response.Write "<table width=601 border=0 cellspacing=0 cellpadding=0>"                           
Response.Write "<tr><td class=tekst>Side " & currentPage & " av " & totalPages & "</td></tr>"
Response.Write "<tr><td class=tekst>Antall treff funnet : " & adoRs.RecordCount & "</td></tr>"
Response.Write "<tr><td class=tekst>Søke resultater for : " & Request.QueryString("q") & "</td></tr>"
Response.Write "<tr><td class=tekst>&nbsp;</td></tr>"
Response.Write "</table>"
                               
Dim rcount, x

For i = 1 To adoRs.PageSize
        rcount = i
        If currentPage > 1 Then
            For x = 1 To (currentPage - 1)
                rcount = 5 + rcount
            Next
        End If

    If Not adoRs.EOF Then
    strDato = adoRs("DocCreated")

    strDay = Day( strdato )
    if len(strDay) = 1 then
        strDay = "0" & strDay
    end if
       
    strMonth = Month( strdato )
    if len(strMonth) = 1 then
        strMonth = "0" & strMonth
    end if
       
    strYear = Year( strdato )
    if len(strYear) = 1 then
        strYear = "0" & strYear
    end if

    strCreated = strDay & "." & strMonth & "." & strYear
   
    '---------------------------
    Dim strSearchWithin,strSearchFor
    strSearchWithin = adoRs("DocContent")
    strSearchFor= replace(Request.QueryString("q")," ",",")

    dim strAr,j,pos,FndPos,str,newstr
    strAr = split(strSearchFor, ",")

    For j = 0 To UBound(strAr)
        strAr(j) = trim(strAr(j))
    next
    pos = 1
    FndPos = 1
    For j = 0 To UBound(strAr)
        FndPos = instr(1, strSearchWithin, strAr(j),1)
        Do While FndPos<>0
            str = Mid(strSearchWithin, 1, (FndPos-1)+len(strAr(j)))
            newstr = Mid(str, 1, FndPos - 1) & "<B><i>" & Mid(str, FndPos, len(strAr(j))) & "</i></B>"
            'newstr = Mid(str, 1, FndPos - 1) & "<span class=heading>" & Mid(str, FndPos, len(strAr(j))) & "</span>"
            strSearchWithin = replace(strSearchWithin, str, newstr)
            pos = FndPos+len(strAr(j)) + 3
            FndPos = instr(pos, strSearchWithin, strAr(j),1)
        Loop
    next
   
    Response.Write "<table width=601 border=0 cellspacing=0 cellpadding=0>"       
    Response.Write "<tr><td class=tekst>" & rcount & ") <b><a href=""url.asp?url=wp.asp?DocID=" & adoRs("DocId") & """>" & adoRs("DocTitle") & "</a></b></td></tr>"
    'Response.Write "<tr><td class=tekst>URL : " & strCodeBaseUrl & "url.asp?url=wp.asp?DocID=" & adoRs("DocID") & "</b></td></tr>"
    Response.Write "<tr><td class=tekst>" & LEFT(strSearchWithin,300) & "...</td></tr>"
    Response.Write "<tr><td class=tekst><i>Opprettet : " & strCreated & "</i></td></tr>"
    Response.Write "<tr><td class=tekst>&nbsp;</td></tr>"
    Response.Write "</table>"

    adoRs.MoveNext
    End If
Next
                               
If currentPage > 1 Then
    Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?currentPage=" & currentPage - 1 & "&q=" & Server.URLEncode(Request.QueryString("q")) & """>Tilbake</a>"
    Else
    Response.Write "<u style=""color : silver;"">Tilbake</u>"
End If
                               
Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                               
If CInt(currentPage) <> CInt(totalPages) Then
    Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?currentPage=" & currentPage + 1 & "&q=" & Server.URLEncode(Request.QueryString("q")) & """>Neste</a>"
    Else
    Response.Write "<u style=""color : silver;"">Neste</u>"
End If

Else
Response.Write "<b>Beklager, ingen treff i dokumenter.</b><br>Kontroller at du har stavet riktig." & vbcrlf
End If
   
Set adoRs = Nothing   
'-------------------------------------
'SØKER I DOKUMENTER STOPP   
'-------------------------------------   

'--------------------------------------------------------------------------------------------------------------

'-------------------------------------
'SØKER I NYHETER START   
'-------------------------------------   
Set adoRs = CreateObject("ADODB.Recordset")
adoRs.CursorLocation = adUseClient
adoRs.PageSize = recordsToShow
adoRs.CacheSize = recordsToShow
               
Select Case UBound(strKeyword)
    Case 0     adoRs.Open "SELECT NewsID,NewsTittel,Ingress,Regdato FROM tblWPNews Where NewsTittel LIKE '%" & strKeyword(0) & "%' OR Ingress LIKE '%" & strKeyword(0) & "%' OR BrodTekst LIKE '%" & strKeyword(0) & "%' ORDER BY RegDato DESC", adoCn, adOpenForwardOnly, adLockReadOnly, adCmdText
    Case 1        adoRs.Open "SELECT NewsID,NewsTittel,Ingress,Regdato FROM tblWPNews Where NewsTittel LIKE '%" & strKeyword(0) & "%' OR NewsTittel LIKE '%" & strKeyword(1) & "%' OR Ingress LIKE '%" & strKeyword(0) & "%' OR Ingress LIKE '%" & strKeyword(1) & "%' OR BrodTekst LIKE '%" & strKeyword(0) & "%' OR BrodTekst LIKE '%" & strKeyword(1) & "%' ORDER BY RegDato DESC", adoCn
    Case 2        adoRs.Open "SELECT NewsID,NewsTittel,Ingress,Regdato FROM tblWPNews Where NewsTittel LIKE '%" & strKeyword(0) & "%' OR NewsTittel LIKE '%" & strKeyword(1) & "%' OR NewsTittel LIKE '%" & strKeyword(2) & "%' OR Ingress LIKE '%" & strKeyword(0) & "%' OR Ingress LIKE '%" & strKeyword(1) & "%' OR Ingress LIKE '%" & strKeyword(2) & "%' OR BrodTekst LIKE '%" & strKeyword(0) & "%' OR BrodTekst LIKE '%" & strKeyword(1) & "%' OR BrodTekst LIKE '%" & strKeyword(2) & "%' ORDER BY RegDato DESC", adoCn
    Case Else    adoRs.Open "SELECT NewsID,NewsTittel,Ingress,Regdato FROM tblWPNews Where NewsTittel LIKE '%" & strKeyword(0) & "%' OR NewsTittel LIKE '%" & strKeyword(1) & "%' OR NewsTittel LIKE '%" & strKeyword(2) & "%' OR Ingress LIKE '%" & strKeyword(0) & "%' OR Ingress LIKE '%" & strKeyword(1) & "%' OR Ingress LIKE '%" & strKeyword(2) & "%' OR BrodTekst LIKE '%" & strKeyword(0) & "%' OR BrodTekst LIKE '%" & strKeyword(1) & "%' OR BrodTekst LIKE '%" & strKeyword(2) & "%' ORDER BY RegDato DESC", adoCn
    End Select

%>
<br><br>
<hr class="tekst" size="1">
<table width="601" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="601" height="<%=strHeight%>"></td>
  </tr>
  <tr>
    <td class="heading" width="601" height="15"><font color="#<%=strTMouseover%>">Søk i nyheter</font></td>
  </tr>
</table>
<%

If Not adoRs.EOF Then

totalpages = adoRs.PageCount
adoRs.AbsolutePage = currentPage

Response.Write "<table width=601 border=0 cellspacing=0 cellpadding=0>"                                   
Response.Write "<tr><td class=tekst>Side " & currentPage & " av " & totalPages & "</td></tr>"
Response.Write "<tr><td class=tekst>Antall treff funnet : " & adoRs.RecordCount & "</td></tr>"
Response.Write "<tr><td class=tekst>Søke resultater for : " & Request.QueryString("q") & "</td></tr>"
Response.Write "<tr><td class=tekst>&nbsp;</td></tr>"
Response.Write "</table>"

For i = 1 To adoRs.PageSize
        rcount = i
        If currentPage > 1 Then
            For x = 1 To (currentPage - 1)
                rcount = 5 + rcount
            Next
        End If

    If Not adoRs.EOF Then
    strDato = adoRs("RegDato")

    strDay = Day( strdato )
    if len(strDay) = 1 then
        strDay = "0" & strDay
    end if
       
    strMonth = Month( strdato )
    if len(strMonth) = 1 then
        strMonth = "0" & strMonth
    end if
       
    strYear = Year( strdato )
    if len(strYear) = 1 then
        strYear = "0" & strYear
    end if

    strCreated = strDay & "." & strMonth & "." & strYear   
   
    Response.Write "<table width=601 border=0 cellspacing=0 cellpadding=0>"       
    Response.Write "<tr><td class=tekst>" & rcount & ") <b><a href=""url.asp?url=wp.asp?NewsID=" & adoRs("NewsId") & """>" & adoRs("NewsTittel") & "</a></b></td></tr>"
    Response.Write "<tr><td class=tekst>" & LEFT(adoRs("Ingress"),310) & "...</td></tr>"
    Response.Write "<tr><td class=tekst><i>Opprettet : " & strCreated & "</i></td></tr>"
    Response.Write "<tr><td class=tekst>&nbsp;</td></tr>"
    Response.Write "</table>"

    adoRs.MoveNext
    End If
Next
                               
If currentPage > 1 Then
    Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?currentPage=" & currentPage - 1 & "&q=" & Server.URLEncode(Request.QueryString("q")) & """>Tilbake</a>"
    Else
    Response.Write "<u style=""color : silver;"">Tilbake</u>"
End If
                               
Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                               
If CInt(currentPage) <> CInt(totalPages) Then
    Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?currentPage=" & currentPage + 1 & "&q=" & Server.URLEncode(Request.QueryString("q")) & """>Neste</a>"
    Else
    Response.Write "<u style=""color : silver;"">Neste</u>"
End If

Else
Response.Write "<b>Beklager, ingen treff i nyheter.</b><br>Kontroller at du har stavet riktig." & vbcrlf
End If
'-------------------------------------
'SØKER I NYHETER SLUTT   
'-------------------------------------       
                           
Set adoRs = Nothing
%>
<br><br>

I denne koden så highlighter den kun den som er i strSearchWithin
Jeg vil at jeg skal kunne kalle opp en funksjon.

Feks i coden her:
    Response.Write "<table width=601 border=0 cellspacing=0 cellpadding=0>"
    Response.Write "<tr><td class=tekst>" & rcount & ") <b><a href=""url.asp?url=wp.asp?DocID=" & Highlight(adoRs("DocId")) & """>" & adoRs("DocTitle") & "</a></b></td></tr>"
    Response.Write "<tr><td class=tekst>" & Highlight(LEFT(adoRs("DocContent")),300)) & "...</td></tr>"
    Response.Write "<tr><td class=tekst><i>Opprettet : " & strCreated & "</i></td></tr>"
    Response.Write "<tr><td class=tekst>&nbsp;</td></tr>"
    Response.Write "</table>"
Avatar billede keysersoze Ekspert
30. oktober 2003 - 15:06 #11
det hjalp mig nu ikke meget :o/

problemet er at jeg ikke ved hvad det er du vil - og i hvilken forbindelse det oprindelige spørgsmål kommer ind
Avatar billede mortency Nybegynder
30. oktober 2003 - 15:55 #12
//K

Jeg lukker spm og opprettet et nytt.
Avatar billede keysersoze Ekspert
30. oktober 2003 - 16:04 #13
og hvorfor accepterer du så cool_casper's svar?
Avatar billede mortency Nybegynder
30. oktober 2003 - 16:06 #14
Sorry gav point til feil person. Skal gi deg nye point. Se nytt spm!
Avatar billede cool_casper Nybegynder
30. oktober 2003 - 17:01 #15
lol
Avatar billede cool_casper Nybegynder
30. oktober 2003 - 17:04 #16
link?
Avatar billede cool_casper Nybegynder
30. oktober 2003 - 17:04 #17
Skal jeg ikke bare give point'ne til key?
Avatar billede mortency Nybegynder
31. oktober 2003 - 10:01 #18
Cool Casper

Takk for hjelpen! Behold pointene. Jeg har gitt Keysersoze point også!
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester

IT-JOB

Capgemini Danmark A/S

Open Application (Denmark)

Forsvarsministeriets Materiel- og Indkøbsstyrelse

Teknologirådgiver inden for AI-området til Teknologiafdelingen

Politiets Efterretningstjeneste

IT-løsningsarkitekt i PET

Netcompany A/S

IT Consultant