Force Character Wrap.

A

Adam

Hello is there a function in ASP that can force a database result to
automatically wrap at say.. 25 characters in length?

Reason for this is because I have a database and people could go in and put
a message like

"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"

and when it is displayed on the site it will make the layout all messed up.

If someone knows how to do this I would be very great ful, Thanks!
 
S

Steven Burn

Function FormatOutput(strData)
Select Case Len(strData)
Case < 25 'Under 25 chars
'Do something
Case > 25 'Over 25 chars
'Do something
End Select
End Function

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
 
T

Tim Slattery

Adam said:
Hello is there a function in ASP that can force a database result to
automatically wrap at say.. 25 characters in length?

Reason for this is because I have a database and people could go in and put
a message like

"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"

and when it is displayed on the site it will make the layout all messed up.

If someone knows how to do this I would be very great ful, Thanks!

Keep in mind that your browser will wrap text, but will only break it
where there's a space. The long string of Ms above has no space, so
the browser won't break it. It's likely that the actual data will have
spaces (though, of course, I know nothing about your data) and will
break properly.

I mention this because our testing department made my web app's
display distort terribly by using a long string of characters with no
spaces. In real life, the string would be words separated by spaces,
and would break and wrap appropriately. I wasted far too much time
figuring that out!
 
D

Dave Anderson

Adam said:
Hello is there a function in ASP that can force a database
result to automatically wrap at say.. 25 characters in
length?

Reason for this is because I have a database and people
could go in and put a message like

"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"

and when it is displayed on the site it will make the layout
all messed up.

If you really want to avoid displaying such messages, why not simply reject
them instead of inserting them into your DB? Warn the user that his message
will be rejected (or that it was not recorded due to the long string), and
leave it at that.

The easiest way to test for long unbroken strings is with a regular
expression. Try something like this:

JScript:
if (/\w{25}/.test(myVar)) ... //-- Reject string

VBScript:
Dim rx
Set rx = New RegExp
rx.Pattern = "\w{25}"
If rx.Test(strMyValue) Then
... ' Reject the string
End If

VBScript RegExp Object:
http://msdn.microsoft.com/library/en-us/script56/html/vsobjregexp.asp

Regular Expression Syntax (applies to both VBScript and JScript):
http://msdn.microsoft.com/library/en-us/script56/html/js56jsgrpregexpsyntax.asp


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top