ASP
  Home arrow ASP arrow Page 2 - Enhancing Readability with ASP
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Enhancing Readability with ASP
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 60
    2004-06-22

    Table of Contents:
  • Enhancing Readability with ASP
  • Trim the String
  • What Does 07/13/2004 Mean?
  • How to Use It

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Enhancing Readability with ASP - Trim the String


    (Page 2 of 4 )

    First, the string is trimmed, removing any whitespace at either end. If the string is actually longer than what you've specified as the maximum desired length, the whole string is returned. Otherwise, we move on in the function, trying to find the nearest space to the desired length. This is accomplished by employing ASP's inStrRev to search through the string in reverse. We give it the desired length, and that's where it starts searching, backwards. The reason for doing it backwards is that you'll only end up with a string slightly smaller than the desired length, but never larger.

    If no space can be located, then we are forced to chop the string. Though this may not seem too desirable, we really have to do it, otherwise the string wouldn't be shortened at all. It shouldn't cause too much grief, as the only case where this would happen would be with long strings not containing words, as with serial numbers.

    For most other string, this will work perfectly well. We use the character '…' because it produces the '...' in the width of only one ASCII character, and not three full periods. You can adjust this as you see fit.

    A sample use of this would be:

    strLong = " This string is too long! "

    strTrimmed = NeatTrim( strLong, 13 )

    response.write( strTrimmed )


    This would produce:

    This string...

    Now, for the user's sake, it would be a good idea of somehow indicating what the full string really is. This can be done through the HTML 4.0 attribute of 'title'. Here's an example:

    strLong = " This string is too long! "

    strTrimmed = NeatTrim( strLong, 13 )

    response.write( "<span title=""" & strLong & """>" & strTrimmed & "</span>" )


    With that code, they will still see the neatly trimmed string, but when they move their mouse over it, they get the full string in the little 'title' popup. Now let's move onto the second.

    More ASP Articles
    More By Justin Cook


       · Thank you for this handy function!Just one thing to note: I had to change the...
     

    ASP ARTICLES

    - Using MySQL with ASP
    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT