Article Preview with substring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Trmbne2000
    New Member
    • Aug 2007
    • 5

    Article Preview with substring

    Hello,

    I'm developing a press release system, and on the homepage, they want a short preview of the article. I would consider using left(...) to take the first x characters, however there is HTML in the articles. If you take a substring, you could end up with unclosed html tags, or end up somewhere in the middle of a tag (<a href="http://ww) Does anyone know of any functions that will let you take the proper amount of text, and leave the html tags intact?
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi Trmbne2000,

    You could write a function to do this that would parse through the string removing the html tags and creating a new string for you. This example below should help you to build something to suit your needs.
    Code:
     
    flgHTML = False
    For i = 0 to 50 
      If Mid(sString, i, 1) = "<" Then
    	 flgHTML = True
    	 i=i+1
      End If
     
      If Mid(sString, i, 2) = "/>" Then
    	 flgHTML = False
    	 i=i+2
      End If
      If flgHTML = False Then sNewString = sNewString + Mid(sString, i, 1)
    Next
    Let me know how you get on,

    Dr B

    Comment

    Working...