Posted By

elightbo on 10/08/09


Tagged

textmate text function ASP


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

benrudolph


Shorten text ASP function


 / Published in: ASP
 

  1. Function shortenText(text, length, append)
  2. if (Len(text) > length) then 'shorten if greater than length
  3. descriptionArr = Split(text, " ") 'split words into an array
  4. text = ""
  5. for i = 0 to UBound(descriptionArr)
  6. descriptionWord = descriptionArr(i)
  7. if (Len(descriptionWord) + Len(text) + 1 <= length) then 'if new word plus sentence being put together is shorten than length'
  8. text = text & descriptionWord & " "
  9. else
  10. exit for
  11. end if
  12. next
  13. if append <> "" then
  14. text = text & append
  15. end if
  16. shortenText = text
  17. else
  18. shortenText = text
  19. end if
  20. End Function

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: MarcusT on December 28, 2009

BEWARE of using this on anything other than short sentences - string concatenation in a loop (line 8) is VERY inefficient and will quickly lead to significant performance problems (such as server CPU hogging) when processing long inputs with this function!

See my article at ASP101 on this subject for more information on this issue (including alternatives).

Posted By: elightbo on January 4, 2010

Yes, very good point. Thank you for pointing to your article. I have been using this to pull a very shortened description from an RSS feed.

You need to login to post a comment.