Function
This example is a database query example, through the split function of the query field is cut. An example for flexible control of queries or for developing deeper applications.
<%
Dim Conn
Dim Rs
Dim J
Dim I
Set Conn = Server.CreateObject ("Adodb.connection")
Conn.Open "Driver={microsoft Access driver (*.mdb)};d bq=" & Server.MapPath ("Myweb\database\guestbook.mdb")
Set Rs = Server.CreateObject ("Adodb.recordset")
The ' strsql= ' select * from Guestbook ' is equivalent to the next sentence.
Strsql=splittext ("Title Content", "", "select", "From Guestbook", ",")
Rs.Open strSQL, Conn, 1, 3
Call Rsfieldshow ("title content", "", "Title: Content:", "<br/> <br/>")
' J=rs.fields.count
' For I=0 to (J-1)
' Response.Write ("& i+1 &" field Name: & Rs.fields (i). Name & "<br><br>")
' Next
%>
<%
In the ASP, the field (Content) to be queried is passed as a string with a prefix (pretext), suffix (lasttext).
' requires the prefix to produce an array, the same number as the query field.
Sub rsfieldshow (Byval content,byval splitmark,byval pretext,byval lasttext)
On Error Resume Next
Everystring=split (Content,splitmark) ' gets an array of strings and assigns values.
Everypretext=split (Pretext,splitmark)
Everylasttext=split (Lasttext,splitmark)
For I=lbound (everystring) to UBound (everystring)
Response.Write Everypretext (i) & Rs (everystring (i)) & Everylasttext (i) ' Output results
Next
End Sub
' Outputs a string in the specified format.
Function Splittext (Byval content,byval splitmark,byval pretext,byval lasttext,byval)
On Error Resume Next
Dim STRQ
Strq=split (Content,splitmark) ' gets an array of strings and assigns values.
For I=lbound (STRQ) to UBound (STRQ) ' uses functions to get the upper and lower bounds of the array.
Splittext=splittext & Strq (i) & Splitchar ' Portfolio
Next
Splittext=left (Splittext,len (Splittext)-1) ' Removes the last symbol.
Splittext=pretext & Splittext & Lasttext ' plus prefix and return.
End Function
%>
You can configure the database path, field query, etc. according to the actual situation.
Output results:
Title: A case of Split function in ASP
Content: www.webjx.com more and more content!