This actually works. I guess that it counts from the end backwards. I'm
splitting up the text into 400 character chunks (breaking at a space so as
not to cut a word in half).
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSend.Click
'Remove ending Carriage Returns and/or Line Feeds
While txtMsg.Text.EndsWith(vbCr) Or txtMsg.Text.EndsWith(vbLf)
If txtMsg.Text.EndsWith(vbLf) = True Then txtMsg.Text =
txtMsg.Text.Remove(txtMsg.Text.Length - 1, 1)
If txtMsg.Text.EndsWith(vbCr) = True Then txtMsg.Text =
txtMsg.Text.Remove(txtMsg.Text.Length - 1, 1)
End While
'Split the text into chunks separated by Carriage Returns
Dim msg() As String = Split(txtMsg.Text.Replace(vbCrLf, vbCr), vbCr)
For i As Integer = 0 To msg.Length - 1
If msg(i).Length <= 399 Then
SendToHost(msg(i) & vbCr)
Else
While msg(i).Length > 399
Dim at As Integer = msg(i).LastIndexOf(" ", 399, 399)
Dim tmp As String = Trim(msg(i).Substring(0, at))
SendToHost(tmp & vbCr)
msg(i) = Trim(msg(i).Substring(at))
End While
If msg(i) <> "" Then SendToHost(msg(i) & vbCr)
End If
Next
End Sub
"Terry Olsen" <to******@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I have a string that is approximately 600 characters. I need to divide up
the string into 400 character chunks. I'm having trouble with using
LastIndexOf. The following code returns a value of 594.
value=msg(i).LastIndexOf(" "c)
The following code returns a value of -1
value=msg(i).LastIndexOf(" "c,1)
The following code returns an exception saying that the count parameter is
out of range.
value=msg(i).LastIndexOf(" "c,1,399)
I need help! Thanks.