Recommended: Common errors and solutions in database calls in ASP The following are some errors in database calls in ASP programs that are often encountered during virtual machine maintenance. Now we collect and organize them as follows: Cannot open the registry keyword (8007000e) Microsoft OLE DB Provider for ODBC Drivers Error '8007000e' [Micr
Extracting long articles from the database always hinders the layout of the web page.
So, I want to extract a part of the characters fixedly, and then there is... a replacement afterward.
1. Principle:
Determine whether the length of the article exceeds the specified length. If it exceeds the specified length, only the university of the specified length will be displayed, otherwise it will be displayed in full.
2. Functions involved:
len(): Returns the string length or the byte length of the variable.
| The following is the quoted content: <script language=vbs> cnbruce=my name is cnbruce len_cn=len(cnbruce) alert(len_cn) </script> |
[Ctrl A All Selection Tips: You can modify some code first, and then press Run]
[Ctrl A All Selection Tips: You can modify some code first, and then press Run]
left(): Intercept the first part of a string
| The following is the quoted content: <script language=vbs> cnbruce=my name is cnbruce left_cn=left(cnbruce,10) alert(left_cn) </script> |
[Ctrl A All Selection Tips: You can modify some code first, and then press Run]
3. Main program: determine whether the content length is greater than the given value, and do the corresponding operation according to the results.
| The following is the quoted content: <script language=vbs> text=123 4567 8fds90 abcde fghxcfv i=10 if len(text)>i then 'If the text length is greater than the given value text=left(text,i) 'Then extracts the string of i bits in the previous section alert (text&...) else alert (text) end if </script> |
[Ctrl A All Selection Tips: You can modify some code first, and then press Run]
4. Application in ASP
The above is in client script debugging, which is similar to ASP: the most important thing is the function function.
| The following is the quoted content: <% text=rs(content) 'assign the database field value to a variable i=10 'Define fixed size if len(text)>i then 'If the text length is greater than the given value text=left(text,i) 'Then extracts the string of i bits in the previous section response.write (text&...) else response.write (text) end if %> |
5. For convenience, make a function
| The following is the quoted content: <% function console(content,i) if len(content)>i then content=left(content,i) response.write (content&...) else response.write (content) end if end function %> |
The above is a function, and you can call it directly below.
<l conleft(rs(content),10)%>
OK, I believe that these problems should be NO PROBLEM in the future
In order to solve the problem of intercepting in Chinese and English, it is recommended that you use the following functions:
| The following is the quoted content: Function gotTopic(str,strlen) if str= then gotTopic= exit function end if dim l,t,c,i str=replace(replace(replace(replace(replace(str, , ),",chr(34)),>,>),<,<) l=len(str) t=0 for i=1 to l c=Abs(Asc(Mid(str,i,1)))) if c>255 then t=t 2 else t=t 1 end if if t>=strlen then gotTopic=left(str,i) & … exit for else gotTopic=str end if next gotTopic=replace(replace(replace(replace(replace(gotTopic, , ),chr(34),"),>,>),<,<) End Function |
Share: How to use session when verifying management login People who are new to ASP have never known session very well. I am talking about the simple use of session when doing simple background login: 1: login.htm I won't say much about this page. Add the form to write the administrator nickname and give the text box username.