A case of Split function in ASP

Source: Internet
Author: User
Tags array query split
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!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.