views:

38

answers:

2

Well I have been able to figure this out but what I want to do is make my string have a new line after 20 chars. I know how to find how many chars the string has but not how to insert environment.newline at 20 chars.

I am using this to find the string length

If string.Length > 20 then
'Need to be able to insert environment.newline at 20 chars
Else
'Normal string
End If
A: 

Hi there.

If string.Length > 20 Then
            sTest = sTest.Insert(19, Environment.NewLine)
        End If

EDIT:

I think the index should be 19, or it could be 20, you might need to experiment with that.

Cheers. Jas.

Jason Evans
+1  A: 

You need to use a loop: (Tested)

For index As Integer = 20 * (str.Length \ 20) To 0 Step -20
    str = str.Insert(index, Environment.NewLine)
Next

If the string can be very long, you should use a StringBuilder instead.

SLaks
If I am using a listbox how could I make it insert the rest of the line like this.Listbox1.Items.Insert(1, otherpartofline)
xZerox
You can call `Substring(index, Math.Min(index + 20, str.Length))` inside the loop.
SLaks