word wrap

N

news.pandora.be

I want to display a string in a table but when a word in the string is
longer then 40 letters it won't wrap. Does anyone know how I can fix this ?

Thanx

Wannes
 
N

news.pandora.be

And how would I have te do that ?

Curt_C said:
where would you expect it to wrap? if it's a single, uninterrupted, string
of characters the browser has no idea where to break it, besides it's not
right to break it most likely. You'll have to build a custom string reader
to insert a "<br>" or linebreak (if displayed in a textbox, etc).

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


this
 
A

Aaron Bertrand [MVP]

What kind of word is longer than 40 letters? Where would it make sense to
break up such a word? Exactly in half, after 20 characters, after 32
characters, 5 characters from the end, ...?
 
N

news.pandora.be

It's in a sort of message board so I cant realy controle what will be
displayed in the table.
I have to make shure that if someone has put in such long words my table
will still be displayed as it should.
Therefor I'm looking for an ASP-code that places an "<BR>" into my string if
there are words longer than 40 letters in it. It doesn't realy matter to me
where the words are broken as long as they are.

gr.

Wannes
 
A

Aaron Bertrand [MVP]

I would do something like this when you STORE the data (then you don't have
to do it every time you display it).

data = request.form("data")
datas = split(data, " ")
for i = 0 to ubound(datas)
if len(datas(i))>40 then
tmp = ""
for i = 1 to len(datas(i)) step 40
tmp = tmp & "<br>" & mid(str, i, 40)
next
datas(i) = tmp
end if
next
data = join(datas, " ")
' now replace single apostrophes with two, insert into db, etc.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
 
A

Aaron Bertrand [MVP]

tmp = tmp & "<br>" & mid(str, i, 40)

OOPS! Change str to datas(i) here.
 
J

Jeff Cochran

And how would I have te do that ?

Something Like:

NewString = ""
StringLength = Len(WordString)
For i = 1 to (StringLength/40)
NewString = NewString & Left(WordString,40) & "<br>" & VbCrLf
StringLength = StringLength - 40
WordString = Right(WordString,StringLength)
Next
Response.Write NewString

Note, this isn't tested and it only breaks the string into 40
character lines, doesn't break on words or spaces.

But there's probably a WordWrap function floating around that
someone's already written. Hang on...

Yep. Google finds your answer:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId=6220

Jeff
 
E

Evertjan.

news.pandora.be wrote on 17 mei 2004 in
microsoft.public.inetserver.asp.general:
It's in a sort of message board so I cant realy controle what will be
displayed in the table.
I have to make shure that if someone has put in such long words my
table will still be displayed as it should.
Therefor I'm looking for an ASP-code that places an "<BR>" into my
string if there are words longer than 40 letters in it. It doesn't
realy matter to me where the words are broken as long as they are.

this simple j(ava)script script breaks all words
longer than 40 chars long into 40 char parts
ended by a - and a space:

t = t.replace(/(\S{40})/g,"$1- ")


======================

same in vbscript [longer]:

Set regEx = New RegExp
regEx.Pattern = "(\S{40})"
regEx.Global = True
t = regEx.Replace(t, "$1- ")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top