Click to See Complete Forum and Search --> : Wrap Text in vb.net


daniel50096230
August 12th, 2009, 10:43 PM
I have the following code in my vb.net:



lbl.Text = lbl.Text & "<table width=""100%"" border=""1"" bordercolor=""#111111"" cellpadding=""0"" cellspacing=""1"" style=""border-collapse: collapse"">"
lbl.Text = lbl.Text & "<tr>"
lbl.Text = lbl.Text & "<td class=""tableHeader2"" style=""height: 42px; max-width: 4%; text-align: center; FONT-WEIGHT: bold; FONT-SIZE: 8px; COLOR: #000000; FONT-FAMILY: Arial; BACKGROUND-COLOR: #cccccc;"">"
lbl.Text = lbl.Text & "GRN"
lbl.Text = lbl.Text & "</td>"
lbl.text=lbl.text & "</tr>"

lbl.Text = lbl.Text & "<tr>"
lbl.Text = lbl.Text & "<td style=""text-align: center;"">" + ShortenDescription(dsDetails.Tables(0).Rows(b).Item("GRNNo").ToString(),5)
lbl.Text = lbl.Text & "</td>"
lbl.text=lbl.text & "</tr>"


Public Function ShortenDescription(ByVal str As String, ByVal len As Integer) As String
If String.IsNullOrEmpty(str) Then
Return String.Empty
ElseIf str.Length > len Then
Return String.Format("{0}...", str.Substring(0, len))
Else
Return str
End If
End Function



in the GRNNo, there are around 10 character, but I would like to wrap the text after 5 character. However, although I had create a function to make it wrap, but it will display "12345..." rather than wrap the text.Anyone can teach me how to wrap the text?

HanneSThEGreaT
August 13th, 2009, 12:54 AM
Why don't you just add an Enter where you want it to be wrapped ¿

daniel50096230
August 13th, 2009, 01:00 AM
What do you means by add an Enter??

HanneSThEGreaT
August 13th, 2009, 01:23 AM
Use Environment.Newline or vbCrLf in your ShortenDescription function where you cut the text.