Recommended: ASP highlights case-insensitive keywords Today, I encountered a problem: how to highlight case-insensitive keywords in a web page, such as: text abcaBcabCaBCabcaBCa, keyword bc, in case-insensitive situation, there are 6 matches in total. Then the abcaBcabCaBCabcaBCa is displayed on the web page. Many people think of it as a replace function. The prototype is Replace(string, find, replacewith[,
In the past two days, I have learned the EVAL function of ASP. It feels very practical. If used properly, it can reduce the amount of code written and make the code more concise and clear.
Prototype of EVAL function:
EVAL (expression)
where expression is a string parameter, can be an expression, can be a variable, or even a statement. But they all appear in the form of strings.
For example
b=EVAL(A=5)
This code means to judge whether the value of variable A is equal to 5, which is equal to return TRUE, and does not equal to return FALSE. Equivalent to b=(A=5). However, the flexibility of this function lies in the fact that its parameters exist in the form of strings. This way I can construct a string, which is equivalent to executing a statement that string.
For example:
b=EVAL(A)
This code returns the value of variable A. Since ASP is implicitly defined, an empty string is returned when A is not defined.
In example:
b=EVAL(CustFunction(2,3))
This code executes the function CustFunction(2,3) and returns the return value to b. What do you think of when you see this? Well, polymorphic.
Since the parameters of the EVAL function are strings, I can reasonably construct strings to achieve many things that seem impossible.
The following piece of code is the code that uses the EVAL function to construct the link URL. Has a certain degree of versatility.
Dim zID, zOrder, zOrderBy, zCurPage
Dim zPageCount, zURL
Dim zMM(), zMMPara()
redim zMM(0)
redim zMMPara(0)
Public Sub AddPara(Para, Default, ParaType)
ReDim Preserve zMM(UBound(zMM) + 1)
ReDim Preserve zMMPara(UBound(zMM))
If ParaType = 1 Then
zMM(UBound(zMM)) = Para & = & Default
Else
zMM(UBound(zMM)) = Para & = & Default &
End If
zMMPara(UBound(zMM)) = Para
End Sub
Public Function GetURL(URL)
Dim i, tS
tS =
For i = 1 To UBound(zMM)
If Eval(zMM(i)) = False Then
tS = tS & & & Mid(zMMMPara(i), 2) & = & Eval(zMMMPara(i))
End If
Next
If Len(tS) > 0 Then
GetURL = URL & ? & Mid(tS, 2)
Else
GetURL = URL
End If
End Function
Public Function GetNav(Index)
Dim tS
If zPageCount = 1 Then
GetNav =
End If
Select Case Index
Case 1
If zCurPage = 1 Then
GetNav =
Else
tS = zCurPage
zCurPage = 1
GetNav = <span><a href= & GetURL(zURL) & >Home</a></span>
zCurPage = tS
End If
Case 2
If zCurPage = 1 Then
GetNav =
Else
tS = zCurPage
zCurPage = zCurPage - 1
GetNav = <span><a href= & GetURL(zURL) & >Previous page</a></span>
zCurPage = tS
End If
Case 3
If zCurPage = zPageCount Then
GetNav =
Else
tS = zCurPage
zCurPage = zCurPage + 1
GetNav = <span><a href= & GetURL(zURL) & >Next Page</a></span>
zCurPage = tS
End If
Case 4
If zCurPage = zPageCount Then
GetNav =
Else
tS = zCurPage
zCurPage = zPageCount
GetNav = <span><a href= & GetURL(zURL) & >Last Page</a></span>
zCurPage = tS
End If
End Select
End Function
This code makes full use of the EVAL function to construct URLs on the four parameters of the page zID, zOrder, zOrderBy, zCurPage. And has certain versatility. Just make appropriate modifications.
Share: Use XML serialization to implement program configuration files When some applications exit, they will write some setting values to the file so that they can be called the next time the program starts. This file is collectively called a configuration file. For example: Windows' minesweeper will appear at the last closed position every time it is started, because the minesweeper writes the current position into the configuration file when it exits. Early configuration file implementation