| | |
Translating English to Pig Latin
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 88
Reputation:
Solved Threads: 0
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
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)
Private Sub xTranslateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xTranslateButton.Click Dim strInput As String Dim str1stCharacter As String Dim strOutput As String Dim intStringLength As Integer strInput = Me.xEnterText.Text str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1) If str1stCharacter = "A" Or str1stCharacter = "E" _ Or str1stCharacter = "I" Or str1stCharacter = "O" _ Or str1stCharacter = "U" Or str1stCharacter = "Y" Then strOutput = strInput & "-WAY" Else intStringLength = Len(strInput) strOutput = Microsoft.VisualBasic.Right(strInput, 3) _ & "-" & Microsoft.VisualBasic.Left(strInput, 2) & "AY" End If Me.xAnswerLabel.Text = "The Pig Latin Translation of " & strInput & " is " & strOutput & "." End Sub
•
•
Join Date: Oct 2007
Posts: 88
Reputation:
Solved Threads: 0
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.
here's the new code.
VB.NET Syntax (Toggle Plain Text)
Private Sub xTranslateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xTranslateButton.Click Dim strInput As String Dim str1stCharacter As String Dim strOutput As String Dim intStringLength As Integer strInput = Me.xEnterText.Text str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1) If str1stCharacter = "A" Or str1stCharacter = "E" _ Or str1stCharacter = "I" Or str1stCharacter = "O" _ Or str1stCharacter = "U" Or str1stCharacter = "Y" _ Or str1stCharacter = "1" Or "2" Or "3" Or "4" Or "5" Or "6" Or "7" Or "8" Or "9" Or "0" Then strOutput = strInput & "-WAY" ElseIf str1stCharacter = "Q" Or "W" Or "R" Or "T" Or "P" Or "S" _ Or "D" Or "F" Or "G" Or "H" Or "J" Or "K" Or "L" Or "Z" _ Or "X" Or "C" Or "V" Or "B" Or "N" Or "M" Then intStringLength = Len(strInput) strOutput = Microsoft.VisualBasic.Right(strInput, 3) _ & "-" & Microsoft.VisualBasic.Left(strInput, 2) & "AY" End If Me.xAnswerLabel.Text = "The Pig Latin Translation of " & strInput & " is " & strOutput & "." End Sub
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!
<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!
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Class Library In VS 2003
- Next Thread: MDI form
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





