Hi
I have a little problem with a "Do" loop. What I try to build is a function that works the same way as a textbox in for example indesign does. If you add a textbox there and the add some text that doesnt fit in the first lie it automatically add a "-" sign as a last charachter on that line and then continue with the text on the second line and so on.
Here's what I got so far..
I would like my function to return a string like this..
This is my very long
string and I must
say its waaaaaaaaaa-
aaaaaaaaaaaaytolong
I realize that the loop some how is infinite and I probably must change a length or something, but I can't figure it out. Can someone please take a look and check what might be wrong?
Regards
I have a little problem with a "Do" loop. What I try to build is a function that works the same way as a textbox in for example indesign does. If you add a textbox there and the add some text that doesnt fit in the first lie it automatically add a "-" sign as a last charachter on that line and then continue with the text on the second line and so on.
Here's what I got so far..
HTML:
Function MakeMeChoppedString(ByVal MyString As String, ByVal ReplaceWith As String, ByVal iLength As Integer) As String
MyString = MyString & ("¤")
Dim MyTempString1 As String = MyString
Dim MyTempString2 As String = MyString
Dim MyTempString3 As String = MyString
Dim MyTempString4 As String = String.Empty
If MyString.Length > (iLength + 1) Then
Do Until (MyTempString2.Length + iLength) < (iLength + 1)
MyTempString3 = MyTempString2
If MyTempString3.Length > iLength Then
If MyTempString3.Substring(MyTempString3.Length - 1) = (" ") Then
MyTempString1 = MyTempString3.Substring(0, (iLength))
Else
If InStr(MyTempString3, " ") Then
MyTempString1 = MyTempString3.Substring(0, (iLength))
MyTempString1 = MyTempString1.Substring(0, InStrRev(MyTempString1, " ") - 1)
Else
Response.Write("heres where my problem starts...")
MyTempString1 = MyTempString1.Substring(0, iLength) & ("-")
iLength = iLength + 1
End If
End If
Else
MyTempString1 = MyTempString3
End If
MyTempString2 = MyTempString3.Remove(0, MyTempString1.Length)
MyTempString4 += MyTempString1 & ("¤")
Loop
End If
Return MyTempString4.Replace("¤", ReplaceWith).ToString
End Function
Literal1.Text = (MakeMeChoppedString("This is my very long string and I must say its waaaaaaaaaaaaaaaaaaaaaaytolong", ("<br>"), 20))
I would like my function to return a string like this..
This is my very long
string and I must
say its waaaaaaaaaa-
aaaaaaaaaaaaytolong
I realize that the loop some how is infinite and I probably must change a length or something, but I can't figure it out. Can someone please take a look and check what might be wrong?
Regards