none
Pig Latin Translator

    Question

  • I need to find if a word entered starts with 2 constants or a vowel and a constant if the word starts with 2 constants I want to move the 2 constants to the end of the word and add "ay". If the entered word starts with a constant and a vowel I want to move the first letter of the word at the end and add "ay". the adding "ay" part is super easy but finding if the word starts with the combinations is harder. some examples of words are - 

    Happy = appyh + ay = appyhay

    Child = Ildch + ay = Ildchay


    Sunday, March 12, 2017 7:12 PM

Answers

  • Hi

    Maybe something like this:

    ' New Form1 with textbox1, textbox2
    ' and button1
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
        Dim vowels As New List(Of String)
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            vowels.AddRange({"a", "e", "i", "o", "u"})
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            TextBox2.Text = Pe(TextBox1.Text)
        End Sub
        Function Pe(s As String) As String
            ' returns unchanged if no matches found
            Dim endword As String = s
            Dim ss() As Char = s.ToLower.Substring(0, 2).ToCharArray
            If Not vowels.Contains(ss(0)) Then
                If Not vowels.Contains(ss(1)) Then
                    endword = s.Substring(2, s.Length - 2) & s.Substring(0, 2) & "ay"
                Else
                    If vowels.Contains(ss(1)) Then
                        endword = s.Substring(1, s.Length - 1) & s.Substring(0, 1) & "ay"
                    End If
    
                End If
            End If
            Return endword
        End Function
    End Class
    NOTE: no attention given to word upper/lower case


    Regards Les, Livingston, Scotland

    • Marked as answer by BadNewsHughes Sunday, March 12, 2017 8:21 PM
    Sunday, March 12, 2017 8:02 PM

All replies

  • Hi

    Maybe something like this:

    ' New Form1 with textbox1, textbox2
    ' and button1
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
        Dim vowels As New List(Of String)
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            vowels.AddRange({"a", "e", "i", "o", "u"})
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            TextBox2.Text = Pe(TextBox1.Text)
        End Sub
        Function Pe(s As String) As String
            ' returns unchanged if no matches found
            Dim endword As String = s
            Dim ss() As Char = s.ToLower.Substring(0, 2).ToCharArray
            If Not vowels.Contains(ss(0)) Then
                If Not vowels.Contains(ss(1)) Then
                    endword = s.Substring(2, s.Length - 2) & s.Substring(0, 2) & "ay"
                Else
                    If vowels.Contains(ss(1)) Then
                        endword = s.Substring(1, s.Length - 1) & s.Substring(0, 1) & "ay"
                    End If
    
                End If
            End If
            Return endword
        End Function
    End Class
    NOTE: no attention given to word upper/lower case


    Regards Les, Livingston, Scotland

    • Marked as answer by BadNewsHughes Sunday, March 12, 2017 8:21 PM
    Sunday, March 12, 2017 8:02 PM
  •  This is a pretty common homework assignment which we can help you with but,  are not suppose to just write for you.  Next time,  please post the code you have written and we will help you fix it.  There are many questions about this homework assignment on the internet that you can get ideas from of ways to go about doing this if you do a few google searches.   8)

    If you say it can`t be done then i`ll try it

    Sunday, March 12, 2017 8:42 PM