During dynamic web page programming, if the article title is too long and exceeds the table width, the new line will be automatically wrapped, which will affect the layout of the webpage. Therefore, we usually extract a part of the characters in a fixed manner, and then use... .
Here, we will give a brief description based on the "Deep Space whole site system" program instance.
1. Principle:
Determine whether the length of an article exceeds the specified length. If the length exceeds the specified length, only the text of the specified length is displayed. Otherwise, the text is displayed completely.
2. involved functions:
For more information about function usage, see the VBScript function manual:
Len () returns the length of the string or the length of the variable in bytes.
Mid () returns the string starting from the nth character to take M characters. Its format is mid ("string", n, m ).
Left (): truncates the first part of a string.
<%
Title = RS ("content") 'assigns the database field value to a variable
I = 10' defines a fixed size of 10
If Len (title)> I then', if the text length is greater than the given value
Title = left (title, I) 'extracts the I-bit string from the front
Response. Write (Title &"...")
Else
Response. Write (title)
End if
%>