A string has no line feeds or cariage retunrs or spaces, need to insert a vbCrLf

J

Jason

When users fill out my text area field, there is a chance that there
will be no line feeds or cariage returns or spaces and just one really
long word. THIS CAUSES A MAJOR PROBLEM! What I am trying to do is
force a vbCrLf if a string is long than 80 characters in a row. So if
a string is a total of 500 characters with no line feeds, spaces, or
returns, I want to force a vbCrLf every 80 characters so that is
doesn't overflow my preview text field on the next page.

Any suggestions on how the algorithm would be for this in VBscript
ASP?

Thanks,
Jason
 
A

Adrienne

Gazing into my crystal ball I observed (e-mail address removed) (Jason) writing in
When users fill out my text area field, there is a chance that there
will be no line feeds or cariage returns or spaces and just one really
long word. THIS CAUSES A MAJOR PROBLEM! What I am trying to do is
force a vbCrLf if a string is long than 80 characters in a row. So if
a string is a total of 500 characters with no line feeds, spaces, or
returns, I want to force a vbCrLf every 80 characters so that is
doesn't overflow my preview text field on the next page.

Any suggestions on how the algorithm would be for this in VBscript
ASP?

Thanks,
Jason

How about:
for each word in split(request.form("test")," ")
if len(trim(word)) > 5 then
test = test & left(word,5) & vbcrlf & right(word,len(word)-5) & " "
else
test = test & word & " "
end if
next
 
T

Tom B

Dim iLoop
Dim sWorking
Dim sSection
for iLoop = 0 to len(theString) step 80
sSection=mid(theString,iLoop,80)
if instr(sSection," ") = 0 OR instr(sSection,vbCrLf)=0 then
sWorking=sWorking & sSection & vbCrLf
else
sWorking=sWorking & sSection
end if
next
 
B

Bob Lehmann

I have trouble remembering something that happened last week, and you recall
a thread from over three years ago? :>)

Bob Lehmann
 
A

Aaron Bertrand - MVP

I vaguely recalled dealing with the situation before (and was surprised I
hadn't entered an article about it). Though you can easily force carriage
returns by placing text within a fixed-width table or div.

It took me about 20 minutes to find that thread, because of my initial
choice of keywords...
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top