Forum Moderators: open

Message Too Old, No Replies

Is it possible? Carriage Return...

         

joker197cinque

8:16 am on Jun 11, 2004 (gmt 0)

10+ Year Member




<table width="760" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n
aaaaaaaaaaaaaaaaaaaaaaa</td>
</tr>
</table>

Is it possible to avoid this?

I would like a carriage return although a string without any spaces...

Is it possible?

Any help appreciated.

Best regards.

Fabrizio

[edited by: BlobFisk at 9:29 am (utc) on June 12, 2004]
[edit reason] Removed scroll - \n is a manual line break. [/edit]

bill

8:30 am on Jun 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You mean <br>?

joker197cinque

8:52 am on Jun 11, 2004 (gmt 0)

10+ Year Member



Yes a BR should be OK but I have no control on where and when put this BR...

I should write my own vbscript function to add a CRLF every, for example, 40-50 chrs without spaces...

I guess if it was possible only by CSS o HTML layout.

Regards.

ronin

11:03 am on Jun 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There are probably several solutions to this using CSS.

The most immediate one that I can think of is to use this in the html:


<table><tr>
<td>a a a a a a a a a a a a a a a a a a a a a a a</td>
</tr></table>

and this in the CSS:


td {letter-spacing: 0.1em;}

joker197cinque

1:28 pm on Jun 11, 2004 (gmt 0)

10+ Year Member




There are probably several solutions to this using CSS.
The most immediate one that I can think of is to use this in the html:

<table><tr>
<td>a a a a a a a a a a a a a a a a a a a a a a a</td>
</tr></table>

I can't do this...there are some users that insert some text and If they insert a link so long? (they did!)


and this in the CSS:

td {letter-spacing: 0.1em;}

Nope...it doesn't work.

It only renders the space between words but scroll bar still remains...

Any help?

Best regards.

Fabrizio

R1chard

1:42 pm on Jun 11, 2004 (gmt 0)

10+ Year Member



Try <wbr> (a soft-break) or &#8203; (a zero-width space):

[quirksmode.org...]

The former works in Netscape 2-4 and IE 2-6.
The latter is W3C and works in Moz, Opera and Safari but doesn't work in IE (it actually prints some garbage)!

korkus2000

2:03 pm on Jun 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not use a string function on the server-side to break up strings that go over a certian length?

john_k

2:12 pm on Jun 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You didn't originally mention that you were using vbScript/ASP, so I suppose the solution belongs in that forum. Here are two functions from an Include file that do what you want.


<SCRIPT LANGUAGE=VBScript RUNAT=Server>
' #########################################################################
' WrapText
' Description: Used to wrap text
' Parameters:
' sText String The text that is to be wrapped
' Returns: String Text with <br /> inserted at wrap points
' #########################################################################
Function WrapText(sText, lMaxWidth)

Dim sReturn
Dim sRemainder
Dim lMark

sRemainder = sText
sReturn = ""
Do While Len(sRemainder) > lMaxWidth
lMark = InstrRev(sRemainder, " ", lMaxWidth)
If lMark = 0 Then
lMark = Instr(sRemainder, " ")
End If
If lMark > 0 Then
If sReturn <> "" Then
sReturn = sReturn & "<br />" & Left(sRemainder, lMark - 1)
Else
sReturn = Left(sRemainder, lMark - 1)
End If
If lMark < Len(sRemainder) Then
sRemainder = Mid(sRemainder, lMark + 1)
Else
sRemainder = ""
End If
Else
' no spaces left in string, so we're done
Exit Do
End If
Loop

If sReturn <> "" Then
WrapText = sReturn & "<br />" & sRemainder
Else
WrapText = sRemainder
End If

End Function

Function WrapTextWHangingIndent(sText, lMaxWidth, lIndentWidth)

Dim sReturn
Dim sRemainder
Dim lMark
Dim sIndent
Dim lLineWidth
Dim bIsFirstLine
Dim i

sRemainder = sText
sReturn = ""
lLineWidth = lMaxWidth
bIsFirstLine = True
sIndent = ""
Do While Len(sRemainder) > lLineWidth
lMark = InstrRev(sRemainder, " ", lLineWidth)
If bIsFirstLine Then
lLineWidth = lMaxWidth - lIndentWidth
For i = 0 To (lIndentWidth - 1)
sIndent = sIndent & "&nbsp;"
Next
bIsFirstLine = False
End If
If lMark = 0 Then
lMark = Instr(sRemainder, " ")
End If
If lMark > 0 Then
If sReturn <> "" Then
sReturn = sReturn & "<br />" & sIndent & Left(sRemainder, lMark - 1)
Else
sReturn = Left(sRemainder, lMark - 1)
End If
If lMark < Len(sRemainder) Then
sRemainder = Mid(sRemainder, lMark + 1)
Else
sRemainder = ""
End If
Else
' no spaces left in string, so we're done
Exit Do
End If
Loop

If sReturn <> "" Then
WrapTextWHangingIndent = sReturn & "<br />" & sIndent & sRemainder
Else
WrapTextWHangingIndent = sRemainder
End If

End Function
</SCRIPT>

joker197cinque

3:41 pm on Jun 11, 2004 (gmt 0)

10+ Year Member



I know that I can use a function...but i don't want to overhead my server...

however the first one i tried doesn't work, I create my own it is little more compact:


<%@ Language=VBScript %>
<%

Function WrapText(sText, lMaxWidth)

sOriginal = sText
iPointer = 0

for idx = 1 to len(sText)

if idx = 1 then
sText = mid(sText, 1, lMaxWidth) & " <br /> "
iPointer = iPointer + 1
elseif idx mod lMaxWidth = 0 then
sText = sText & mid(sOriginal, (lMaxWidth*iPointer)+1, lMaxWidth) & " <br /> "
iPointer = iPointer + 1
end if

next

WrapText = sText

End Function

Response.Write(WrapText("abcdefghilmnopqrstuvzabcdefghilmn [red]\n[/red]
opqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvza[red]\n[/red]
bcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmn[red]\n[/red]
opqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvz[red]\n[/red]
abcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghi[red]\n[/red]
lmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrst[red]\n[/red]
uvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvzabcdef[red]\n[/red]
ghilmnopqrstuvzabcdefghilmnopqrstuvzabcdefghilmnopqrstuvz", 5))
Response.Write(WrapText("", 5))
%>


Thankx for help.

Regards.

Fabrizio

P.s. Sorry for the indentation, I'm not able to insert it to work neither with [ pre ] neither with [ code ]

[edited by: BlobFisk at 9:27 am (utc) on June 12, 2004]
[edit reason] Fixed scrolling - \n is a manual line break/ [/edit]

john_k

4:22 pm on Jun 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What exactly didn't work?

The difference between your function and the one I posted is that yours is going to always break the text at the provided length, regardless of whether or not there are any spaces. The one I posted will look for a space to the left of the maxlength point and break there if one is found.