webForumDet fria alternativet
Logga in / Bli medlem

replace - wordleft

ASP

2 svar · 171 visningar · startad av Jesper T

Medlem sedan nov. 20017 144 inlägg
Trådstart#1

Hej jag skulle vilja kombinera dessa saker i en och samma presentation, hur gör man detta lättast månne??


Function WordLeft(strText, intNoOfWords)	
Dim arrText, strippedText, I	
arrText = Split(strText, " ")	
If UBound(arrText) => intNoOfWords Then		
For I = 0 To (intNoOfWords - 1)			
If i = (intNoOfWords - 1) Then 				
strippedText = strippedText & arrText(i) & "..."			
Else				
strippedText = strippedText & arrText(i) & " "			
End if		
Next	
Else		
strippedText = strText	
End If	
WordLeft = strippedText
End Function
%>

presenteras med:

<%Response.write wordleft(RS("text"),5)

Vill kombinera med:

      <%response.write replace(rs("text"),Query ,"<font style='BACKGROUND-COLOR: #33CCFF'>" & Query & "</font>",1,-1,vbTextCompare)%>

MVH

//Jesper

Medlem sedan maj 200010 687 inlägg
#2
<%response.write wordleft(replace(rs("text"),Query ,"<font style='BACKGROUND-COLOR: #33CCFF'>" & Query & "</font>",1,-1,vbTextCompare))%>

eller ännu bättre:

Function QueryMarked(str, sQuery)
	replace(str, sQuery , "<font style='BACKGROUND-COLOR: #33CCFF'>" & Query & "</font>", 1, -1,vbTextCompare)
End Function

response.write wordleft(QueryMarked(rs("text"),Query))
Medlem sedan nov. 20017 144 inlägg
#3

Microsoft VBScript compilation error '800a03ea'

Syntax error

/sok/search.asp, line 151

Function QueryMarked(str, sQuery)
^
Står det då!
Det som inte heller finns med i koden är ju siffran som anger meningens längd i ord.

<%Response.write wordleft(RS("text"),5)'<<<<<<<<<5 meningens längd i ord>>>>>>>>>>>>>>

//Jesper

255 ms totalt · 4 externa anrop · v20260731065814-full.51f67c91
126 ms — deklarationer (db)
0 ms — hämta statistik (cache)
126 ms — hämta tråd, inlägg och bilagor (db)
118 ms — ändringar (db)