4 Replies - 2109 Views - Last Post: 17 April 2011 - 03:59 PM Rate Topic: -----

#1 Arikon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-April 11

Programming English to pig latin. HELP

Posted 17 April 2011 - 11:11 AM

I am making an english to pig latin translator and I cannot quite get this right! For some reason i can always get the first word to translate but the other words jumble together and sometimes repeat themselves.

The rules for this program are as follows: To translate an English word into a pig Latin word, place the first letter of the English word (if it is not a vowel) at the end of the English word and add the letters “ay.” If the first letter of the English word is a vowel, place it at the end of the word and add “y.” Using this method, the word “jump” become “umpjay,” the word “the” becomes “hetay” and the word “ace” becomes “ceay”. Blanks between words remain blanks.

So far this is what I've got:

Public Class Form1

    Private Sub btnTran_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTran.Click
        Dim Sentence As String, letter As String, wordI As String, word1 As String, word As Double, wordamount As Double, counter As Integer = 0, current As Double
        txtOutput.Text = ""
        Try
            Sentence = (txtInput.Text).ToUpper
            wordamount = Wordcount(Sentence)
            lbl1.Text = wordamount
            Do Until counter = wordamount
                Sentence = Sentence & " "
                If counter = 0 Then
                    word = Sentence.IndexOf(" ")
                    word1 = Sentence.Substring(0, word)
                Else
                    word = Sentence.IndexOf(" ", counter)
                    word1 = Sentence.Substring((txtOutput.Text.Length), word)
                End If
                letter = Microsoft.VisualBasic.Left(word1, 1)
                counter += 1
                If word1.Length > 1 Then
                    If letter = "A" Or letter = "E" Or letter = "I" Or letter = "O" Or letter = "U" Then
                        wordI = word1.Substring(1) & letter & "Y"
                        txtOutput.Text = txtOutput.Text & " " & wordI
                    ElseIf letter = "B" Or letter = "C" Or letter = "D" Or letter = "F" Or letter = "G" Or letter = "H" Or letter = "J" Or letter = "K" Or letter = "L" Or letter = "M" Or letter = "N" Or letter = "P" Or letter = "Q" Or letter = "R" Or letter = "S" Or letter = "T" Or letter = "V" Or letter = "W" Or letter = "X" Or letter = "Y" Or letter = "Z" Then
                        wordI = word1.Substring(1) & letter & "AY"
                        txtOutput.Text = txtOutput.Text & wordI
                    Else
                        MessageBox.Show("Please Use Letters", "Error")
                    End If
                Else
                    txtOutput.Text = txtOutput.Text & word1
                End If
            Loop
        Catch
            MessageBox.Show("Invalid Entry", "Error")
        End Try
    End Sub

    Function Wordcount(ByVal Sentence)
        Return System.Text.RegularExpressions.Regex.Matches(Sentence, "\w+").Count
    End Function

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtInput.Text = ""
        txtOutput.Text = ""
        lbl1.Text = ""
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Programming English to pig latin. HELP

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9206
  • View blog
  • Posts: 34,588
  • Joined: 12-June 08

Re: Programming English to pig latin. HELP

Posted 17 April 2011 - 11:37 AM

Quote

I am making an english to pig latin translator and I cannot quite get this right! For some reason i can always get the first word to translate but the other words jumble together and sometimes repeat themselves.


Would you provide some more information? Can you give an example of a word(s) you are using, what the output is looking like, and what the output should be?
Was This Post Helpful? 0
  • +
  • -

#3 Arikon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-April 11

Re: Programming English to pig latin. HELP

Posted 17 April 2011 - 12:00 PM

Sure, some examples are
Apple gives me PPLEAY which is correct, but
Apple and cherry gives me PPLEAYD CHNAYY RAY
What i need it to give me is PPLEAY NDAY HERRYCAY

Seattle gives me EATTLESAY which is right but
Seattle Washington gives me EATTLESAY SHINGTAY
What it should give me is EATTLESAY ASHINGTONWAY

Thanks for any help you can give me.
Was This Post Helpful? 0
  • +
  • -

#4 Arikon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-April 11

Re: Programming English to pig latin. HELP

Posted 17 April 2011 - 02:52 PM

Well thanks for any help anyways but I'm going a different route with the code since this is making me pull my hair out.
Was This Post Helpful? 0
  • +
  • -

#5 dbasnett  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 603
  • Joined: 01-October 08

Re: Programming English to pig latin. HELP

Posted 17 April 2011 - 03:59 PM

    Dim smplSentence As String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    Dim vowelSnd As String = "aeiouy"

    Private Sub Button1_Click(sender As System.Object, _
                              e As System.EventArgs) Handles Button1.Click

        smplSentence = smplSentence.Replace(",", "").ToLower 'get rid of commas

        Dim words() As String = smplSentence.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)

        For x As Integer = 0 To words.Length - 1
            Dim sb As New System.Text.StringBuilder(words(x))
            Debug.Write(sb.ToString & " > ")
            If vowelSnd.Contains(sb(0)) Then 'start with vowel?
                'yes
                sb.Append("-")
                sb.Append(sb(0))
                sb.Append("y")
                sb.Remove(0, 1)
                words(x) = sb.ToString
                Debug.WriteLine(sb.ToString)
            Else
                'no
                sb.Append("-")
                sb.Append(sb(0))
                sb.Append("ay")
                sb.Remove(0, 1)
                words(x) = sb.ToString
                Debug.WriteLine(sb.ToString)
            End If
        Next
    End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1