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:
- 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?
- 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 ) & "…"
else
strToTrim = left( strToTrim, inStrRev( strToTrim, " ", desiredLength + 1 ) -1 ) & "…" 'no carriage return here
end if
end if
neatTrim = trim( strToTrim )
End Function
Next: Trim the String >>
More ASP Articles
More By Justin Cook