Using ASP to realize the UBB function of forum (II.)

Source: Internet
Author: User
Tags comparison count expression numeric numeric value
It should be noted that the InStr of the function we want to use is its last selectable parameter compare, because our UBB code needs to be case insensitive, and by default the function InStr is to be binary matched, that is to say, case-sensitive, so remember This one
The value of the compare parameter should be set to 1 to meet our requirements.
Replace function
Returns a string in which a specified number of substrings are replaced with another substring.
Replace (expression, find, replacewith[, compare[, count[, start]])
Parameters
Expression
Required option. A string expression contains a substring to override.
Find
Required option. The substring being searched for.
ReplaceWith
Required option. The substring to replace.
Start
Options available. The location at which to start searching for substrings in expression. If omitted, the default value is 1. When associating with count, you must use the
Count
Options available. The number of execution substring substitutions. If omitted, the default value is-1, which means that all possible substitutions are made. Must be associated with the start
Use.
Compare
Options available. Indicates the numeric value of the comparison type to use when calculating the substring. For numeric values, see the "Settings" section. If omitted, the default value is 0, which means that binary comparisons must be made.
Set up
The Compare parameter can have the following values:
Constant
Value
Describe
Vbbinarycompare
0
Performs a binary comparison.
vbTextCompare
1
Performs a text comparison.
return value
Replace returns the following values:
If
Replace return
Expression is zero length
0 length string ("").
Expression is Null
Error.
Find is zero length
copy of the expression.
ReplaceWith is zero length
A copy of the expression that deletes all the content specified by the find parameter.
Start > Len (expression)
0 length string.
Count is 0
copy of the expression.
Here we should note that nature is also the replacement of the Compare optional parameters, so that we are in the UBB code to replace the entire time to ensure that the case insensitive.
In fact, the implementation of the UBB code of the program's core ideas are the same, the realization of one of them, the other is also solved. Here we have a more difficult and representative http://www.alixixi.com/program/a/... The implementation of the grammar as an example to explain how to achieve him in detail:
First of all, we can analyze, in a passage, to achieve this function, in fact, is the form of http:// The xxx.xxx.xxx string is found and appropriately replaced and replaced all the way, that is, you have to try to remember where each step is in order to replace it in turn, and here is the function code to implement the UBB syntax: (There are detailed comments in it).
Function Linkurls (strinput)
Dim icurrentlocation
Dim Ilinkstart
Dim Ilinkend
Dim Strlinktext
Dim Stroutput
' Initialize variable
Strlinktext= ""
Stroutput= ""
Icurrentlocation=1
Do While INSTR (Icurrentlocation,strinput, "Ilinkstart=instr (icurrentlocation,strinput, [url]", 1) "Record the start position
Ilinkend=instr (Icurrentlocation+1,strinput, "" target= "_blank" > ", 1) <>0 ' find UBB syntax string
Ilinkstart=instr (Icurrentlocation,strinput, "[url]", 1) ' record start position
Ilinkend=instr (Icurrentlocation+1,strinput, "", 1) "Record End position
If Ilinkend=0 then Ilinkend=len (strinput) +1
Select Case Mid (strinput,ilinkend-1,1)
Case ".", "!", "?"
Ilinkend=ilinkend-1 ' eliminates extra punctuation
End Select
Stroutput=stroutput & Mid (strinput,icurrentlocation,ilinkstart-icurrentlocation)
Strlinktext=replace (Mid (strinput,ilinkstart+5,ilinkend-ilinkstart-5), "[/url]", "")
Stroutput=stroutput & "" & Strlinktext & ""
Icurrentlocation=ilinkend ' records the current cursor position
Loop
Stroutput=stroutput & Mid (strinput,icurrentlocation)
Linkurls=replace (stroutput, "[/url]", "", 1,-1,1)
End Function
OK, through the above implementation http://www.alixixi.com/program/a/... function, we can, and so on to achieve the other UBB syntax functions, limited to space, I will not be the one to describe, you can put these functions into a file, forming a UBB code function library, so that you can easily be referenced in your program.
How, through our own efforts, now our forum can also fully support the UBB code function, our forum will now become colorful, illustrated, and will certainly attract more netizens,:)
For an example of the actual application of the above article, you can access it here: Http://TechTop.Yeah.Net
(All of the above procedures are run through WINDOWS9X/NT,IIS/PWS,ACCESS/SQL7) (Beijing Su Hongsu)


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.