PDA

View Full Version : wordwrap


esthera
01-24-2008, 02:46 PM
can someone help me modify my code below to do wordwrap but not go to the next line if it's in middle of a word


strTextToBeWrapped="helow htisi is test hi how are you today ok ok will htis work"
response.write srtexttobewrapped & "<hr>"
'pdf.addtextpos 500,625 ,strTextToBeWrapped ' & "balance"
myline=625
origstring=strTextToBeWrapped
strLength = Len(OrigString)
intPosition = 1
StrWrapNumber = 30
StrLoop = StrLength\ StrWrapNumber
If StrLoop > 0 then
For LoopStep = 0 to StrLoop
WrapString = Mid(OrigString, intPosition, StrWrapNumber)
' pdf.addtextpos 300,625 ,wrapstring
response.write wrapstring & "<bR>"
myline=myline+10
intPosition = intPosition + StrWrapNumber
Next
Else
Response.Write OrigString
End if

mjlorbet
01-24-2008, 08:15 PM
why don't you just create a div with the runat=server tag and use the InnerText property to write to it, just setup the css on the div to wordwrap (scroll if need be)?

mjlorbet
01-24-2008, 08:21 PM
<!-- Include and position in your output document -->
<div id="WrappingDiv" runat="server" style="width:300px; height:300px; overflow:hidden; white-space:normal; text-align:left;">
</div>


'Server side code
WrappingDiv.InnerText = strTextToBeWrapped;


You could also use:

'Create a new div element on the server side
WrapDiv = new HTMLGenericControl("div")
WrapDiv.Style.Add("width", "300px")
WrapDiv.Style.Add("height", 400px")
WrapDiv.Style.Add("overflow", "hidden")
WrapDiv.Style.Add("white-space", "normal")
WrapDiv.InnerText = strTextToBeWrapped
me.controls.add(WrapDiv)


If this doesn't work it's because my vb's a little rusty, but the principle's right

esthera
01-24-2008, 08:23 PM
problem is i'm really using this with a pdf object where i have to write out each line so I can't do that

angst
01-25-2008, 03:40 PM
I built this a while ago, it might be what your looking for:


Function BreakString(strInput, intBreakPoint)
intStart = 1
intEnd = intBreakPoint
intStringLength = Len(strInput)
strOutput = ""
If intStringLength > intBreakPoint Then
Do While intStart < intStringLength
if(intStart + intBreakPoint > intStringLength) Then
strOutput = strOutput & Mid(strInput, intStart)
else
strOutput = strOutput & Mid(strInput, intStart, intEnd) & "<BR />"
End If
intStart = intStart + intBreakPoint
Loop
End If
BreakString = strOutput
End Function