943,529 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 4216
  • VB.NET RSS
May 4th, 2008
0

Translating English to Pig Latin

Expand Post »
Hey all,

I've got this program where I have to translate a word from English to Pig Latin. I'm sorta on the brink but I'm missing something.

the test words are "ant" and "chair" but they should then turn to "ant-WAY" and "air-chay"

but i'm ending up with "ant-anAY" and "air-ChAY"

and even further I know that I'm kinda cheating on the chair translation because it definitely won't work with any other word that doesn't start with a vowel. Finally is someone enters a numeric value like 56 it should show "56-WAY".

I'm stuck...any help? Code below




VB.NET Syntax (Toggle Plain Text)
  1. Private Sub xTranslateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xTranslateButton.Click
  2.  
  3. Dim strInput As String
  4. Dim str1stCharacter As String
  5. Dim strOutput As String
  6. Dim intStringLength As Integer
  7.  
  8. strInput = Me.xEnterText.Text
  9.  
  10. str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1)
  11.  
  12. If str1stCharacter = "A" Or str1stCharacter = "E" _
  13. Or str1stCharacter = "I" Or str1stCharacter = "O" _
  14. Or str1stCharacter = "U" Or str1stCharacter = "Y" Then
  15.  
  16. strOutput = strInput & "-WAY"
  17. Else
  18. intStringLength = Len(strInput)
  19. strOutput = Microsoft.VisualBasic.Right(strInput, 3) _
  20. & "-" & Microsoft.VisualBasic.Left(strInput, 2) & "AY"
  21. End If
  22. Me.xAnswerLabel.Text = "The Pig Latin Translation of " & strInput & " is " & strOutput & "."
  23. End Sub
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
leroi green is offline Offline
93 posts
since Oct 2007
May 4th, 2008
0

Re: Translating English to Pig Latin

okay, i've got the first part working but I've still got problems with the second part outlining words that start with cons.

here's the new code.

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub xTranslateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xTranslateButton.Click
  2.  
  3. Dim strInput As String
  4. Dim str1stCharacter As String
  5. Dim strOutput As String
  6. Dim intStringLength As Integer
  7.  
  8. strInput = Me.xEnterText.Text
  9.  
  10. str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1)
  11.  
  12. If str1stCharacter = "A" Or str1stCharacter = "E" _
  13. Or str1stCharacter = "I" Or str1stCharacter = "O" _
  14. Or str1stCharacter = "U" Or str1stCharacter = "Y" _
  15. Or str1stCharacter = "1" Or "2" Or "3" Or "4" Or "5" Or "6" Or "7" Or "8" Or "9" Or "0" Then
  16.  
  17. strOutput = strInput & "-WAY"
  18. ElseIf str1stCharacter = "Q" Or "W" Or "R" Or "T" Or "P" Or "S" _
  19. Or "D" Or "F" Or "G" Or "H" Or "J" Or "K" Or "L" Or "Z" _
  20. Or "X" Or "C" Or "V" Or "B" Or "N" Or "M" Then
  21. intStringLength = Len(strInput)
  22. strOutput = Microsoft.VisualBasic.Right(strInput, 3) _
  23. & "-" & Microsoft.VisualBasic.Left(strInput, 2) & "AY"
  24. End If
  25. Me.xAnswerLabel.Text = "The Pig Latin Translation of " & strInput & " is " & strOutput & "."
  26. End Sub
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
leroi green is offline Offline
93 posts
since Oct 2007
May 4th, 2008
1

Re: Translating English to Pig Latin

Try this:
<code>
Dim strInput As String = ""
Dim str1stCharacter As String = ""
Dim strOutput As String = ""
Dim intStringLength As Integer = 0

strInput = Me.xEnterText.Text

str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1)
Select Case str1stCharacter
Case "A", "E", "I", "O", "U", "Y", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
strOutput = strInput & "-WAY"
Case Else
intStringLength = Len(strInput)
strOutput = Microsoft.VisualBasic.Right(strInput, 3) _
& "-" & Microsoft.VisualBasic.Left(strInput, 2) & "AY"
End Select
Me.xAnswerLabel.Text = "The Pig Latin Translation of " & strInput & " is " & strOutput & "."
Exit Sub
</code>

Good Luck!
Reputation Points: 13
Solved Threads: 2
Light Poster
poguemahone is offline Offline
25 posts
since Aug 2007
May 4th, 2008
0

Re: Translating English to Pig Latin

cool, working except with the word "ant" to "ant-way"
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
leroi green is offline Offline
93 posts
since Oct 2007
May 4th, 2008
0

Re: Translating English to Pig Latin

In the Select Case, change str1stCharacter to str1stCharacter.ToUpper.

Select Case str1stCharacter.ToUpper()
Reputation Points: 13
Solved Threads: 2
Light Poster
poguemahone is offline Offline
25 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Class Library In VS 2003
Next Thread in VB.NET Forum Timeline: MDI form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC