Shorten string text in asp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    Shorten string text in asp

    Hi, I am trying to shorten text I get from my database. I have this.


    Code:
    function shortString(ltext,textlength)
    
    	if not isNull(ltext) then
    		if len(lText) > textlength then
    			lIndex = instrRev(left(lText,textlength)," ")
    			if lIndex > -1 then
    				retText = left(ltext,lIndex) & "..."
    			else
    				retText = left(ltext,textlength) & "..."
    			end if
    		else 
    			retText = lText
    		end if
    	else
    		retText = ""
    	end if
    	
    	shortstring = retText
    end function

    and also

    Code:
    <% 
    myString = rs("databasefield")
    myShortString = shortstring(mystring,125)
    response.write(myShortString)
    %>
    I query the database and return many users. Many of the users have content in the "databasefi eld" I need to use an if in the html and have no idea how i should format it without getting error 500.

    Code:
    <%
    If not IsBlank(rs("databasefield")) Then %>
        <p><%=rs("databasefield")%></p>	
    
    
    <%
    End If 
    
    %>
    Any pointers would be great.
    Thanks in advance
    Richard
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It's probably a null, not a blank. You should check for the null in addition to the blank because it could be either.

    Comment

    • sharmajv
      New Member
      • Apr 2013
      • 11

      #3
      TRY THIS
      Code:
      <%
      If not IsBlank(rs("databasefield"))or trim(rs("databasefield")) = "" Then %>
          <p><%=rs("databasefield")%></p>    
       
       
      <%
      Else
      End If 
       
      %>
      And Also Write something in Else Field.

      Comment

      Working...