Question Using For Loops

ningax123

New member
Joined
Nov 21, 2009
Messages
1
Programming Experience
Beginner
So I'm trying out For loops and I want it to go through each letter in the word and everytime there's an "o" add a 2 after it but the code doesn't work. Here's the code so far:

VB.NET:
        Dim word As String = "pokemon"
        Dim test As Integer = 0

        For test = 0 To word.Length - 1
            If word.Chars(test) = "o" Then
                word.Insert(test, "2 ")
            End If

            TextBox1.Text = word
        Next test

    End Sub

What should I do?
 
When using the string.Insert method the return value is that of a new instance of the string.

VB.NET:
        Dim strWord As String = "pokemon"
        Dim strNewWord As String = ""
        Dim intTest As Integer = 0

        For intTest = 0 To strWord.Length - 1
            If strWord.Chars(intTest) = "o" Then
                strNewWord = strWord.Insert(intTest, "2 ")
            End If
        Next intTest

        TextBox1.Text = strNewWord
 
Back
Top