|
 |
asptoday_discuss thread: Reducing field length upon retrieval ...
Message #1 by "Paul" <jacobspd@g...> on Fri, 16 Nov 2001 21:25:03
|
|
Hi all,
I have a query... I am displaying within my browser a URL address that
can be extremely long. What I would like to do is shorten the returned
field e.g. "http://dailynews.yahoo.com/fc/Business/Aviation_Safety/" to
something like "http://dailynews.yahoo.co..." placing the "..." 3 dots at
the end to signify that it has been shortened... Is there a piece of
visual basic code that could be incorporated into my code. The reason I
need this is that I don't know what a certain user may enter and it
destroys the formatting of the table because there are no spaces within
the address...
Here is my code page:
*****************************
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="es-mx">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<title>Favorites Order A-Z</title>
</head>
<body bgcolor="#FFFFFF" topmargin="0" leftmargin="0" marginwidth="0"
marginheight="0" text="#000000" style="background-color: #FFFFFF">
<%
Dim oRSbt
Dim VarUser
VarUser = Session("GifsaUser")
Set oRSbt=Server.CreateObject("ADODB.recordset")
sqltext = "SELECT URLname, URL" _
& " FROM Favorites" _
& " WHERE User_belong = '" & VarUser & "'" _
& " ORDER BY URLname;"
oRSbt.open sqltext, "DSN=Gifsa"
response.write "<table border='0' cellspacing='0' cellpadding='2'
width='228'>"
response.write "<tr><td height='2' colspan='2' width='228'><img
src='images/pixel.gif' width='5' height='2'></td></tr>"
IF oRSbt.EOF then
response.write "<tr><td width='228' colspan='2' align='center'
bgcolor='#D8E1D7'><a href='favoritos.asp' target='_top' class='fav'
title='Click to add Favorite...'>No Favorites found</a></td></tr>"
ELSE
oRSbt.MoveFirst
Do while NOT oRSbt.eof
response.write "<tr><td bgcolor='#D8E1D7' width='22'><img
src='images/pixel.gif' width='4' height='2'>"
response.write "<img src='images/fav_icon.gif' width='13'
height='16'><img src='images/pixel.gif' width='5' height='2'></td>"
response.write "<td bgcolor='#D8E1D7' width='206' class='fav'>" &
oRSbt("URLname") & "<br><a href='" & oRSbt("URL") & "' class='favs'
target='_top'>" & oRSbt("URL") & "</a></td></tr>"
response.write "<tr><td height='1'><img src='images/pixel.gif'
width='1' height='1'></td></tr>"
oRSbt.movenext
loop
END IF
response.write "</table>"
oRSbt.Close
Set oRSbt=nothing
%>
</body>
</html>
*****************************
Any assistance would be greatly appreciated...
Many thanks,
Paul Jacobs
Message #2 by "Jason Salas" <jason@k...> on Sat, 17 Nov 2001 12:21:32
|
|
Hi Paul,
The easiest way would be to use VBScript's LEFT function, which returns a
certain number of characters from a string starting from the left side of
the string.
The syntax structure is:
Left(string,length)
...so for your needs (I'm assuming you want to display the URL within a
Web page and then append the ellipsis ("..."), you could do something like
this within your table code. Replace the:
oRSbt("URL") with:
Left(oRSbt("URL"),25) & "..."
...or just to be on the safe side:
Trim(Left(oRSbt("URL"),25)) & "..."
The latter code will additionally trim off uneccessry spacec from the left
and right side in case a user enters them from a form.
I do something like this already at:
http://www.kuam.com/marketingprograms/headlinegrabber.htm
The big benefit to you as a dev is that you don't have to restructure your
database just to get the characters down.
HTH,
Jason
jason@k...
> Hi all,
>
> I have a query... I am displaying within my browser a URL address that
> can be extremely long. What I would like to do is shorten the returned
> field e.g. "http://dailynews.yahoo.com/fc/Business/Aviation_Safety/" to
> something like "http://dailynews.yahoo.co..." placing the "..." 3 dots
at
> the end to signify that it has been shortened... Is there a piece of
> visual basic code that could be incorporated into my code. The reason I
> need this is that I don't know what a certain user may enter and it
> destroys the formatting of the table because there are no spaces within
> the address...
>
> Here is my code page:
> *****************************
>
> <html>
>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=windows-
1252">
> <meta http-equiv="Content-Language" content="es-mx">
> <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
> <meta name="ProgId" content="FrontPage.Editor.Document">
> <link rel="stylesheet" type="text/css" href="css/styles.css">
> <title>Favorites Order A-Z</title>
> </head>
>
> <body bgcolor="#FFFFFF" topmargin="0" leftmargin="0" marginwidth="0"
> marginheight="0" text="#000000" style="background-color: #FFFFFF">
>
> <%
> Dim oRSbt
> Dim VarUser
> VarUser = Session("GifsaUser")
>
> Set oRSbt=Server.CreateObject("ADODB.recordset")
> sqltext = "SELECT URLname, URL" _
> & " FROM Favorites" _
> & " WHERE User_belong = '" & VarUser & "'" _
> & " ORDER BY URLname;"
> oRSbt.open sqltext, "DSN=Gifsa"
>
> response.write "<table border='0' cellspacing='0' cellpadding='2'
> width='228'>"
> response.write "<tr><td height='2' colspan='2' width='228'><img
> src='images/pixel.gif' width='5' height='2'></td></tr>"
>
> IF oRSbt.EOF then
> response.write "<tr><td width='228' colspan='2' align='center'
> bgcolor='#D8E1D7'><a href='favoritos.asp' target='_top' class='fav'
> title='Click to add Favorite...'>No Favorites found</a></td></tr>"
>
> ELSE
> oRSbt.MoveFirst
> Do while NOT oRSbt.eof
> response.write "<tr><td bgcolor='#D8E1D7' width='22'><img
> src='images/pixel.gif' width='4' height='2'>"
> response.write "<img src='images/fav_icon.gif' width='13'
> height='16'><img src='images/pixel.gif' width='5' height='2'></td>"
> response.write "<td bgcolor='#D8E1D7' width='206' class='fav'>" &
> oRSbt("URLname") & "<br><a href='" & oRSbt("URL") & "' class='favs'
> target='_top'>" & oRSbt("URL") & "</a></td></tr>"
> response.write "<tr><td height='1'><img src='images/pixel.gif'
> width='1' height='1'></td></tr>"
> oRSbt.movenext
> loop
> END IF
> response.write "</table>"
> oRSbt.Close
> Set oRSbt=nothing
> %>
>
> </body>
>
> </html>
> *****************************
>
> Any assistance would be greatly appreciated...
>
> Many thanks,
>
> Paul Jacobs
|
|
 |