-
Translating English to Pig Latin in VB
[Originally posted by Malarkey]
Yeah how would i go about doing this.ÿ
If the word begins with A, E, I, O, or U then add AY to the end of the word. (for example, APPLE becomes APPLEAY).
Otherwise, the first letter of the word is put at the end of the word, and AY is added to the end (for example, SAND becomes ANDSAY)
so Hey ***
-
Re:Translating English to Pig Latin in VB
[Originally posted by Interloper]
Okay...
Dim strInput as String, str1stCharacter as String, strOutput as String, intStringLength as Integer
strInput = txtInput.Text
str1stCharacter = left(strInput, 1)
If str1stCharacter = "A" or str1stCharacter = "E" or str1stCharacter = "I" or str1stCharacter = "O" or str1stCharacter = "U" then
ÿ ÿ strOutput = strInput & "AY"
Else
ÿ ÿ intLen = len(strString1) - 1
ÿ ÿ strOutput = right(strInput, intStringLength) & str1stCharacter & "AY"
End If
lblOutput.Caption = strOutput
...This could be in a click event for a button, assuming you have a text box and a label named txtInput and lblOutput, respectively. Hope this helps because I haven't done VB in a while. :)
-
Use this one...
[Originally posted by Interloper]
Oops...
Dim strInput as String, str1stCharacter as String, strOutput as String, intStringLength as Integer
strInput = txtInput.Text
str1stCharacter = left(strInput, 1)
If str1stCharacter = "A" or str1stCharacter = "E" or str1stCharacter = "I" or str1stCharacter = "O" or str1stCharacter = "U" then
ÿ ÿ strOutput = strInput & "AY"
Else
ÿ ÿ intStringLength = len(strInput) - 1
ÿ ÿ strOutput = right(strInput, intStringLength) & str1stCharacter & "AY"
End If
lblOutput.Caption = strOutput
...Sorry about that, I named a few things wrong.
-
Re:Translating English to Pig Latin in VB
[Originally posted by Chris Carta]
This makes me think (which is dangerous)...
What if you had the word HONOR?ÿ Since it is pronounced like it begins with an O but it begins with an H, you'ld need exception logic for it not to come out as onorHay.
Chris
-
Re:Re:Translating English to Pig Latin in VB
[Originally posted by Interloper]
Then you could put an elseif condition after the if like this...
ElseIf left(strInput, 2) = "HO" then
ÿ ÿ strOutput = right(strInput, intStringLength) & "AY"
...and then the else statement after this. Not too hard to fix. ;)
-
Re:Re:Re:Translating English to Pig Latin in VB
[Originally posted by Chris Carta]
The problem with this would be a word like HONOR and a word like HOME.
Only one fits the exception.ÿ I don't mean to sound anal but I had an assignment like this once with a dialog box that had to use the word 'a' or 'an' depending on the beginning vowel of the next word.ÿ For example:
AN Apple
A Banana
It seems petty, but I hadda say it.
Chris
-
Re:Re:Re:Re:Translating English to Pig Latin in VB
[Originally posted by Interloper]
Fine...
strHOChk = right(strInput, 1)
...this would go right before the If... ElseIf... Else... Condition...
ElseIf left(strInput, 2) = "HO" and strHOChk <> "A" and strHOChk <> "E" and strHOChk <> "I" and strHOChk <> "O" and strHOChk <> "U" then
ÿ ÿ strOutput = right(strInput, intStringLength) & "AY"
...this new ElseIf condition might actually work right. >8[
-
Pig Latin Sentence
I have an assignment where I need to translate a sentence not just a word, how would I do that?
-
By putting every word in the sentence through the logic loops described earlier.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|