Hey i am having trouble creating a piglatin converter using dynamic arrays in vb this is my code so far. the problem is i cant convert multiple words into piglatin

 Private Sub insertWay(ByVal convertWord As String)
    'function will add -way to the words that do not contain vouls
    Const nonVoul As String = "-way"
    outputTextBox.Text = convertWord & nonVoul
  End Sub
  Private Sub toPigLatinToolStripMenuItem_Click(sender As Object, e As System.EventArgs) Handles ToPigLatinToolStripMenuItem.Click
    Dim Word As String
    Word = inputTextBox.Text.Trim
    If Word <> Nothing Then
      If Word.ToString Like "[aeiou]*" Then
        Call insertWay(Word)
      Else
        Call insertAy(Word)
      End If
    End If
    inputTextBox.SelectAll()
  End Sub
  Private Sub insertAy(ByRef Word As String)
    'searches the words to see if they contain vouls
    Dim remainder As String = ""
    Do Until Word = ""
      remainder += Word(0)
      Word = Word.Remove(0, 1)
      If Word.ToLower Like "[aeiouy]*" Then
        outputTextBox.Text = Word & "-" & remainder & "ay"
        Exit Sub
      End If
    Loop
    Call insertWay(remainder)
  End Sub

Instead of assigning all the text from the textbox to the variable Word, use the split function with a space as the delimiter, then loop through the resulting array of words assigning each one to your variable Word. Put the results back into the array then use the join function to rebuild the string and output it to the textbox. For instance if the number 3 element of the array is "cat" you replace "cat" with the translation, "atcay".

what if we arent allowed to use the split function in this project?

You could create your own split function that uses the substring function to find a substring before the space and add that to the array. If that's still no good you could loop through the string of words, use the substring function to isolate the next word, translate it and add it to the outputtextbox. Also you could use the text changed event of the textbox and run the translation routine everytime a space or punctuation is typed, translation on the fly as it were. This becomes quite complicated cause you have to allow for editing. What happens if the user types the backspace, deletes a letter(s) from a word you already translated, etc?

This article has been dead for over six months. Start a new discussion instead.