PDA

View Full Version : wrapping problem


Keltoi
06-09-2003, 11:38 AM
Hi all, hopefully someone can point me in the right direction:

Basically I have a results page which includes a URL. The problem is that
many of the URL's are longer than the page width.
What I need to is some kind of function which will insert a <br> after
X number of characters (unless there is a way to force wrapping).

Any ideas how I would go about this?

Many thanks

raf
06-09-2003, 01:11 PM
I don't quite get it.

You just wan't to print the url as text? Or as a link or so (cause you then don't need to display the complete url --> you can display it as the title or so)?
to simply insert <br />, you can use something like

dim url
url=urlstring 'the url-string
url=Left(url,100) + "<br />" + right(url,(Len(url) - 100))

or if they need to be cut over multiple line, by using a mid fnction or so

Keltoi
06-09-2003, 02:47 PM
Basically the url needs to be displayed on one or more lines depending on the number of characters.

For example if a page can display 100 characters and the URL is only 50 then it is displayed on one line.
If it is 150 then 2 lines and if 350 then 4 lines.

I've tried using your example and placing it in a function but am getting error messages<%
function breakUrl(url)
breakURL = left(url,100) + "<br />" + right(url,(Len(url) - 100))
End Function
%> Is there a way to place the break every XX characters?

raf
06-09-2003, 03:15 PM
do while Len(url) > 100
breakURL = breakURL + left(url,100) + "<br />"
url=right(url,(Len(url) - 100))
loop


this code will loop until the last line contains less then 100 characters.
in each loop, the first 100 characters of url are added to breakURL + a break. Then these hundred characters or cut of the url string.

if you need longer lines, then you need to replace all 100's by a higher value.

If you have errormessages, then tell us what they are. Else we can't help you.

Keltoi
06-09-2003, 03:33 PM
Sorry about that raf,

The original error is no longer happening, Had to add a If statement as any URL less than 100 wasn't being shown. This might be the root cause of the next problem:
the final section of the URL's aren’t being shown.
E.G. If the URL is 326 Then only 3 lines of 100 are shown and not the final 26. - if that makes sense
Current state of play:<%
function breakURL(url)
If len(url) > 100 Then
do while Len(url) > 100
breakURL = breakURL + left(url,100) + "<br />"
url=right(url,(Len(url) - 100))
loop
Else
breakURL = url
End If
End Function
%>

Thanks for your help raf

Keltoi
06-09-2003, 04:41 PM
Seem to have sussed it:<%
function breakURL(url)
do while Len(url) > 100
breakURL = breakURL + left(url,100) + "<br />"
url=right(url,(Len(url) - 100))
loop
If Len(url) < 100 Then
breakURL = breakURL + url
End If
End Function
%> Probably a better way to do it, but seems good.

Thanks for your help raf

raf
06-09-2003, 05:49 PM
indeed. i didn't think of that. Now you don't actually need the if then. so your code could be

<%
function breakURL(url)
do while Len(url) > 100
breakURL = breakURL + left(url,100) + "<br />"
url=right(url,(Len(url) - 100))
loop
breakURL = breakURL + url
End Function
%>

Keltoi
06-09-2003, 05:54 PM
Cool :thumbsup:

raf
06-09-2003, 06:03 PM
Lets optimize some more !

The link should probably be the end of the line (so you also need a break there), so you could set the end codition to any positive stringlengt. As soon as the link is completely processed, the loop will end. (The do loop until will run at least once)
<%
function breakURL(url)
do
breakURL = breakURL + left(url,100) + "<br />"
url=right(url,(Len(url) - 100))
loop until Len(url) < 1
End Function
%>

Keltoi
06-09-2003, 06:08 PM
Not quite following that but gettingMicrosoft VBScript runtime (0x800A0005)
Invalid procedure call or argument: 'right'

Keltoi
06-09-2003, 06:32 PM
Got to head out now, but here's the latest (just added "mid")<%
function breakURL(url)
do while Len(url) > 100
breakURL = breakURL + left(url,100) + "<br />"
url=mid(url, 101)
loop
breakURL = breakURL + url
End Function
%>
Not got your new one to go yet...

L8R