By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,162 Members | 1,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,162 IT Pros & Developers. It's quick & easy.

Shorten string text in asp

100+
P: 229
Hi, I am trying to shorten text I get from my database. I have this.


Expand|Select|Wrap|Line Numbers
  1. function shortString(ltext,textlength)
  2.  
  3.     if not isNull(ltext) then
  4.         if len(lText) > textlength then
  5.             lIndex = instrRev(left(lText,textlength)," ")
  6.             if lIndex > -1 then
  7.                 retText = left(ltext,lIndex) & "..."
  8.             else
  9.                 retText = left(ltext,textlength) & "..."
  10.             end if
  11.         else 
  12.             retText = lText
  13.         end if
  14.     else
  15.         retText = ""
  16.     end if
  17.  
  18.     shortstring = retText
  19. end function
  20.  
  21.  

and also

Expand|Select|Wrap|Line Numbers
  1. <% 
  2. myString = rs("databasefield")
  3. myShortString = shortstring(mystring,125)
  4. response.write(myShortString)
  5. %>
  6.  
I query the database and return many users. Many of the users have content in the "databasefield" I need to use an if in the html and have no idea how i should format it without getting error 500.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. If not IsBlank(rs("databasefield")) Then %>
  3.     <p><%=rs("databasefield")%></p>    
  4.  
  5.  
  6. <%
  7. End If 
  8.  
  9. %>
  10.  
Any pointers would be great.
Thanks in advance
Richard
Apr 5 '13 #1

✓ answered by sharmajv

TRY THIS
Expand|Select|Wrap|Line Numbers
  1. <%
  2. If not IsBlank(rs("databasefield"))or trim(rs("databasefield")) = "" Then %>
  3.     <p><%=rs("databasefield")%></p>    
  4.  
  5.  
  6. <%
  7. Else
  8. End If 
  9.  
  10. %>
  11.  
  12.  
  13.  
And Also Write something in Else Field.

Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,369
It's probably a null, not a blank. You should check for the null in addition to the blank because it could be either.
Apr 5 '13 #2

P: 11
TRY THIS
Expand|Select|Wrap|Line Numbers
  1. <%
  2. If not IsBlank(rs("databasefield"))or trim(rs("databasefield")) = "" Then %>
  3.     <p><%=rs("databasefield")%></p>    
  4.  
  5.  
  6. <%
  7. Else
  8. End If 
  9.  
  10. %>
  11.  
  12.  
  13.  
And Also Write something in Else Field.
Apr 6 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.