ASP Classic: How to truncate a string and add dots at the end.
I needed to cut down the words on our new website and tried to find a script I received about 15 years ago, but I couldn't find it.
Here is another way of doing it that makes the code easier to read and manipulate than other approaches.
What we are doing. We have the string "LongString" with 67 characters. Next, we use LEN to determine how many characters the string contains. If the string is over 45 characters, we will truncate it. To truncate the string, we will use. mid(trim(LongString),1, 45)
Copy
Search Site
Search Google
Else, if it is not over 45 characters, it will display the entire string.
' Character count = 67
LongString = "This is just a very long string that we are going to cut down some."if len(LongString)>45 then
strDisplayName = Decoding(mid(trim(LongString),1, 45)&"...")
else
strDisplayName = LongString
end if
<span title="<%=LongString%>"><%=strDisplayName%></span>