ASP - Inserting line break after 15 characters

Associate
Joined
12 Aug 2004
Posts
1,009
Location
Glasgow, Scotland
Hi there,

How can I insert a line break (<br />) after every 15 characters with ASP (classic)?

What i'm trying to do is output peoples email addresses within table cells but because an email address is all one word i can't figure out how make the string of text automatically go down to the next line.

Cheers for any help,

Steven.
 
Hi mate, thanks for replying.

--------------------------------------------------
Name_| Email______________ | Level
--------------------------------------------------
Fred | [email protected] | 1
James | [email protected]___ | 2
Adam_ | [email protected]___ | 3

As you'll be able to see above i've got a table that shows a users name, email and level in a table with 3 rows. I'd like to stop the email addresses taking up a huge amount of horizontal space by forcing a line break after around 15 characters to keep every nice and neat :)

Cheers,

Steven.
 
Hi again,

I've been mucking about with your example, and looking at W3 Schools and just can't get the 'mid' function to run :confused: Am i doing something wrong?

My code:

Code:
	'declare & initalise variables to execute sql statement
	Dim objSearchSections
	Set objSearchSections = objConn.execute("SELECT SectionID, SectionTitle, SectionText FROM tblSections WHERE SectionTitle LIKE '%"& searchQuery &"%' OR SectionText LIKE '%"& searchQuery &"%' ORDER BY SectionTitle ASC;")%>
	
	<h3 class="section">Content</h3>
	
	<%'let the user know if there is no page results
	If objSearchSections.EOF Then%>No content results<br /><br /><%End If
		
		Dim txt
		txt = "abcdefghijklmnopqrstuvxyz"
		
		'list all section title results
		Do Until objSearchSections.EOF
			Response.Write(objSearchSections("SectionTitle") & "<br />")
			
			If objSearchSections("SectionText") <> "" Then
				Response.Write(Mid(txt),1,5))
			End If
			objSearchSections.MoveNext
		Loop

	'close the recordset connections
	objSearchSections.Close
	Set objSearchSections = Nothing

Error message:

Error Type:
Microsoft VBScript compilation (0x800A0414)
Cannot use parentheses when calling a Sub
/test/SSN/Website/search.asp, line 53, column 28
Response.Write(Mid(txt),1,5))
---------------------------^

Cheers :)
 
joilet said:
Just had a thought, what if the e-mail address was over 30 characters long, my code wouldn't work right!

For that to work, you would need to do some basic math and divide the string length by the max length and ROUND UP to the nearest whole number. Use that number and loop through the string breaking it down a line every 15 characters.

You would be best off creating a function to do that and just pass the e-mail variable through it as you take it from your database or whatever.

I would show you, but i'm knackered and need sleep! Hopefully you can use my example to work on doing what i've just said. Thats assuming you really want to use this method. Unless your doing this to practice messing with strings, the only thing i can think of is if your trying to output this into a plain txt file which im starting to think after seeying your diagram. reminds me of ASCII art and old newsletters! If this is what you're doing then i don't recommend html at all. Read about what i mentioned above about the different line break: vbCrLf

Hi mate,

I've got your original function working, but is their any chance of a very quick example of what your talking about above? ^

I get the idea, but i'm just not entirely sure on how to implement it.
 
Back
Top Bottom