ASP
  Home arrow ASP arrow 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


    (Page 1 of 4 )

    In a further effort to make users perfectly comfortable with our application, this article will explore two functions we can use to make text more readable for the user. We will examine how to neatly trim long strings without chopping words, how to redefine dates into a more human format.

    Introduction

    If you've read any of my past articles, you know that I'm big on usability. The applications we design and build should work for the users, not vise versa. To this end, we strive to place as few limitations on the users as possible, and give them information in a manner that they are accustomed to receiving.

    To make these points a little clearer, I'll explain two situations and then give the functions to help us with those situations. These situations are: limiting string length and providing readable dates.

    Please Limit Title to 50 Charact...

    Notice the heading of this section. This is a very common result of misapplied discipline. You see, we as the developer understand that in a given situation, a title of only 50 characters may be appropriate, as anything longer could crowd the page, or cause other problems. So you have two choices:

    1. You can limit the number of characters the user can type in, either server-side or on the client browser (or both). This has the unfortunate consequence of causing the user severe frustration when the input box simply stops receiving input at 50 characters. They call tech-support to complain that their keyboard is broken, realize it's not, then call you only to find out that they're limited to 50 characters, and then suffer further frustration at having to shorten their title to a far less descriptive slew of words. So no, this isn't a great option. Just think of eBay, wouldn't you just love to be able to leave longer feedback remarks?
    2. Let them type in whatever they want, then when you're surfacing the string on a web page, you just chop it at 50 characters, and tack on a little '...' at the end to signify that it's actually longer. Of course the problem with this is that words get hacked in the middle, as in the case of this title.

    So, as neither of these options seem that great, we've got to come up with some kind of workable solution. And so I have! In harmony with ASP's inherent Trim, RTrim, and LTrim, I've named it NeatTrim. You can use NeatTrim to accept a string of any length, and trim it to the space nearest your desired trimming length. I'll show you the code, and explain the use and benefits thereafter.

    '============================================

    Function neatTrim( strToTrim, desiredLength )

    '=============================================

    strToTrim = trim( strToTrim )

    if len( strToTrim ) < desiredLength then

    neatTrim = strToTrim

    exit function

    else

    if inStrRev( strToTrim, " ", desiredLength ) = 0 then

    strToTrim = left( strToTrim, desiredLength - 1 ) & "&#133;"

    else

    strToTrim = left( strToTrim, inStrRev( strToTrim, " ", desiredLength + 1 ) -1 ) & "&#133;" 'no carriage return here

    end if

    end if

    neatTrim = trim( strToTrim )

    End Function

    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 1 Hosted by Hostway
    Stay green...Green IT