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

Combine two functions

100+
P: 229
Hi, I wonder if someone can tell me if its possible to combine two functions. Both work fine as they are written here, but i need them to work together in the output. I imagine that one must write to combine sNewsTitle and sDescription = statement.

Thanks for any pointers of theory
Richard



function 1 (shorten text)

Expand|Select|Wrap|Line Numbers
  1. Function Shorten(sString, sLength) 
  2. If Len (sString) > sLength Then 
  3.          Shorten = Left(sString,sLength) & "...." 
  4. Else 
  5.          Shorten = sString
  6. End If 
  7. End Function 
  8.  

Expand|Select|Wrap|Line Numbers
  1. Dim sNewsTitle
  2. sNewsTitle= rs("statement")
  3.  
  4.  
  5.  
  6.  
  7. <%
  8. sNewsTitle=Shorten(sNewsTitle,190)    
  9. Response.Write sNewsTitle 
  10. %>

function 2 ( to strip html from string)





Expand|Select|Wrap|Line Numbers
  1. Function RemoveHTML( strText )
  2.     Dim TAGLIST
  3.     TAGLIST = ";!--;!DOCTYPE;A;ACRONYM;ADDRESS;APPLET;AREA;B;BASE;BASEFONT;" &_
  4.               "BGSOUND;BIG;BLOCKQUOTE;BODY;BR;BUTTON;CAPTION;CENTER;CITE;CODE;" &_
  5.               "COL;COLGROUP;COMMENT;DD;DEL;DFN;DIR;DIV;DL;DT;EM;EMBED;FIELDSET;" &_
  6.               "FONT;FORM;FRAME;FRAMESET;HEAD;H1;H2;H3;H4;H5;H6;HR;HTML;I;IFRAME;IMG;" &_
  7.               "INPUT;INS;ISINDEX;KBD;LABEL;LAYER;LAGEND;LI;LINK;LISTING;MAP;MARQUEE;" &_
  8.               "MENU;META;NOBR;NOFRAMES;NOSCRIPT;OBJECT;OL;OPTION;P;PARAM;PLAINTEXT;" &_
  9.               "PRE;Q;S;SAMP;SCRIPT;SELECT;SMALL;SPAN;STRIKE;STRONG;STYLE;SUB;SUP;" &_
  10.               "TABLE;TBODY;TD;TEXTAREA;TFOOT;TH;THEAD;TITLE;TR;TT;U;UL;VAR;WBR;XMP;"
  11.  
  12.     Const BLOCKTAGLIST = ";APPLET;EMBED;FRAMESET;HEAD;NOFRAMES;NOSCRIPT;OBJECT;SCRIPT;STYLE;"
  13.  
  14.     Dim nPos1
  15.     Dim nPos2
  16.     Dim nPos3
  17.     Dim strResult
  18.     Dim strTagName
  19.     Dim bRemove
  20.     Dim bSearchForBlock
  21.  
  22.     nPos1 = InStr(strText, "<")
  23.     Do While nPos1 > 0
  24.         nPos2 = InStr(nPos1 + 1, strText, ">")
  25.         If nPos2 > 0 Then
  26.             strTagName = Mid(strText, nPos1 + 1, nPos2 - nPos1 - 1)
  27.         strTagName = Replace(Replace(strTagName, vbCr, " "), vbLf, " ")
  28.  
  29.             nPos3 = InStr(strTagName, " ")
  30.             If nPos3 > 0 Then
  31.                 strTagName = Left(strTagName, nPos3 - 1)
  32.             End If
  33.  
  34.             If Left(strTagName, 1) = "/" Then
  35.                 strTagName = Mid(strTagName, 2)
  36.                 bSearchForBlock = False
  37.             Else
  38.                 bSearchForBlock = True
  39.             End If
  40.  
  41.             If InStr(1, TAGLIST, ";" & strTagName & ";", vbTextCompare) > 0 Then
  42.                 bRemove = True
  43.                 If bSearchForBlock Then
  44.                     If InStr(1, BLOCKTAGLIST, ";" & strTagName & ";", vbTextCompare) > 0 Then
  45.                         nPos2 = Len(strText)
  46.                         nPos3 = InStr(nPos1 + 1, strText, "</" & strTagName, vbTextCompare)
  47.                         If nPos3 > 0 Then
  48.                             nPos3 = InStr(nPos3 + 1, strText, ">")
  49.                         End If
  50.  
  51.                         If nPos3 > 0 Then
  52.                             nPos2 = nPos3
  53.                         End If
  54.                     End If
  55.                 End If
  56.             Else
  57.                 bRemove = False
  58.             End If
  59.  
  60.             If bRemove Then
  61.                 strResult = strResult & Left(strText, nPos1 - 1)
  62.                 strText = Mid(strText, nPos2 + 1)
  63.             Else
  64.                 strResult = strResult & Left(strText, nPos1)
  65.                 strText = Mid(strText, nPos1 + 1)
  66.             End If
  67.         Else
  68.             strResult = strResult & strText
  69.             strText = ""
  70.         End If
  71.  
  72.         nPos1 = InStr(strText, "<")
  73.     Loop
  74.     strResult = strResult & strText
  75.  
  76.     RemoveHTML = strResult
  77. End Function
  78.  
  79.  








Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. Dim sDescription
  4. sDescription = rs("statement")
  5.  
  6. If IsBlank(rs("statement"))  Then
  7. %> 
  8. <p>This member has not yet written a statement</p>
  9. <%
  10. Else
  11. %> 
  12.  
  13. <p>
  14.  
  15. <%=RemoveHTML(sDescription)%>
  16. </p>
  17. <%
  18. End If
  19. %> 
Apr 17 '13 #1

✓ answered by Rabbit

Shorten(RemoveHTML(statement), 190)

Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,370
You haven't explained how you want to combine them.
Apr 17 '13 #2

100+
P: 229
Hi, Oh sorry. I want the results from the field "statement" to be shortened and also stripped of html.
Thanks for any pointers
Richard
Apr 17 '13 #3

Rabbit
Expert Mod 10K+
P: 12,370
Shorten(RemoveHTML(statement), 190)
Apr 17 '13 #4

Post your reply

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