Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,477 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,874 people online right now. Registration is fast and FREE... Join Now!




Pig Latin more than one word

 
Reply to this topicStart new topic

Pig Latin more than one word, pig latin

Rating  1
cardswin12
14 Feb, 2008 - 07:22 AM
Post #1

New D.I.C Head
*

Joined: 14 Feb, 2008
Posts: 9

Hi, I am trying to make a program where you insert 50 or less characters into a textbox, and it comes out in a messagebox in pig latin. I have my code working for one word, can anybody help me to get it to work when i insert multiple words?
Here is my code so far
CODE

Dim str1stChar, strInput As String
        strInput = txtInput.Text
        str1stChar = txtInput.Text.Substring(0, 1)
        Dim strOutput As String = ""
        Select Case str1stChar.ToUpper
            Case "A", "E", "I", "O", "U"
                strOutput = (strInput.ToUpper & "WAY")
            Case Else
                strOutput = (strInput.Substring(1) & str1stChar & "AY")
        End Select
        MessageBox.Show(strOutput, "Pig Latin")

User is offlineProfile CardPM
+Quote Post

Nayana
RE: Pig Latin More Than One Word
14 Feb, 2008 - 07:44 AM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
You need to split it into an array, and then access it with a For loop. The following will do:

CODE

Dim WordList As String()  'This makes an uninitialised array

WordList = Split(strInput.Text, " ")   'this splits up the text into an array of words.

Dim i As Integer
For i = LBound(WordList) To UBound(WordList) 'Loop from the lower bound of the WordList array to the upper bound.
    'Do stuff here, with WordList(i) being the current word
Next


Hope that helps.
User is offlineProfile CardPM
+Quote Post

cardswin12
RE: Pig Latin More Than One Word
15 Feb, 2008 - 06:46 AM
Post #3

New D.I.C Head
*

Joined: 14 Feb, 2008
Posts: 9

I have that code, but I still do not get the wordlist(i) part.......im sort of lost on what to do with that code?
User is offlineProfile CardPM
+Quote Post

cardswin12
RE: Pig Latin More Than One Word
15 Feb, 2008 - 07:01 AM
Post #4

New D.I.C Head
*

Joined: 14 Feb, 2008
Posts: 9

here is my code so far
CODE

Private Sub btnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTranslate.Click
        Dim str1stChar, strInput As String
        strInput = txtInput.Text
        str1stChar = txtInput.Text.Substring(0, 1)
        Dim strOutput As String = ""
        Dim WordList As String()

        WordList = Split(strInput, " ")

        Dim i As Integer
        For i = LBound(WordList) To UBound(WordList)
            WordList(i) &= txtInput.Text & ControlChars.NewLine
        Next

        Select Case str1stChar.ToUpper
            Case "A", "E", "I", "O", "U"
                strOutput = (strInput.ToUpper & "WAY")
            Case Else
                strOutput = (strInput.Substring(1) & str1stChar & "AY")
        End Select
        MessageBox.Show(strOutput, "Pig Latin")
    End Sub

User is offlineProfile CardPM
+Quote Post

cardswin12
RE: Pig Latin More Than One Word
20 Feb, 2008 - 06:39 AM
Post #5

New D.I.C Head
*

Joined: 14 Feb, 2008
Posts: 9

CODE

Dim str1stChar, strInput As String
        strInput = txtInput.Text
        str1stChar = txtInput.Text.Substring(0, 1)
        Dim strOutput As String = ""

        Dim WordList As String()  'This makes an uninitialised array

        WordList = Split(strInput, " ")   'this splits up the text into an array of words.

        Dim i As Integer
        For i = LBound(WordList) To UBound(WordList) 'Loop from the lower bound of the WordList array to the upper bound.
            WordList(i) = strInput
        Next

        Select Case str1stChar.ToUpper
            Case "A", "E", "I", "O", "U"
                strOutput = (strInput & "WAY")
            Case Else
                strOutput = (strInput.Substring(1) & str1stChar & "AY")
        End Select
        MessageBox.Show(strOutput, "Pig Latin")
    End Sub


I am still confused with the for next statement? Can somebody give me a little help please? It would be appriciated
User is offlineProfile CardPM
+Quote Post

LookNAO
RE: Pig Latin More Than One Word
22 Feb, 2008 - 06:27 AM
Post #6

D.I.C Head
**

Joined: 28 Dec, 2007
Posts: 66



Thanked: 1 times
My Contributions
your close...
When you use the "split" command it populates the string into the "Wordlist" array.

strInput = "Hello this is a test"
WordList = Split(strInput, " ") - seperates via spaces

What you have now:
Wordlist(0) = "Hello"
Wordlist(1) = "this"
Wordlist(2) = "is"
Wordlist(3) = "a"
Wordlist(4) = "test"

[code]

'Since we are seperating, we need something to put it back together with...
Dim strTotalOutput as string

'LBound is the lower array number of Wordlist
'UBound is the upper arra number of Wordlist
For i = LBound(WordList) To UBound(WordList)

'Move this down to here... and we are going through each word...
str1stChar = Wordlist(i).Substring(0, 1)

Select Case str1stChar.ToUpper
Case "A", "E", "I", "O", "U"
strOutput = (strInput & "WAY")
Case Else
strOutput = (Wordlist(i).Substring(1) & str1stChar & "AY")
End Select

'Now since we have seperated each word
'we have to put it back together... and put spaces back between...
strTotalOutput = strTotalOutput + strOutput +" "

'Loop through each word...
next i

MessageBox.Show(strTotalOutput, "Pig Latin")


Now, this is not the most efficient way of doing it, but that will come in time.
:-)




your close...
When you use the "split" command it populates the string into the "Wordlist" array.

strInput = "Hello this is a test"
WordList = Split(strInput, " ") - seperates via spaces

What you have now:
Wordlist(0) = "Hello"
Wordlist(1) = "this"
Wordlist(2) = "is"
Wordlist(3) = "a"
Wordlist(4) = "test"

CODE


'Since we are seperating, we need something to put it back together with...
Dim strTotalOutput as string

'LBound is the lower array number of Wordlist
'UBound is the upper arra number of Wordlist
For i = LBound(WordList) To UBound(WordList)

       'Move this down to here... and we are going through each word...
       str1stChar = Wordlist(i).Substring(0, 1)

       Select Case str1stChar.ToUpper
            Case "A", "E", "I", "O", "U"
                strOutput = (strInput & "WAY")
            Case Else
                strOutput = (Wordlist(i).Substring(1) & str1stChar & "AY")
        End Select

        'Now since we have seperated each word
        'we have to put it back together... and put spaces back between...
        strTotalOutput = strTotalOutput + strOutput +" "

'Loop through each word...
next i

       MessageBox.Show(strTotalOutput, "Pig Latin")


Now, this is not the most efficient way of doing it, but that will come in time.
:-)


User is offlineProfile CardPM
+Quote Post

cardswin12
RE: Pig Latin More Than One Word
22 Feb, 2008 - 06:54 AM
Post #7

New D.I.C Head
*

Joined: 14 Feb, 2008
Posts: 9

Hey, thank you a lot for helping. That definately helped me with the For...Next statement, but my output is still coming out funny. When i put the input "ALL CAN" it comes out in the message box as ALL CANWAY ANCAY. Here is my code as of now
////EDIT//////
I figured out that my code works when all of the first letters of the words i input are consanents, but if the first letter is a vowel, it will not work for some reason
CODE

Dim str1stChar, strInput As String
        strInput = txtInput.Text
        str1stChar = txtInput.Text.Substring(0, 1)
        Dim strOutput As String = ""

        Dim WordList As String()  'This makes an uninitialised array

        WordList = Split(strInput, " ")   'this splits up the text into an array of words.

        Dim i As Integer
        Dim strTotalOutput As String

        'LBound is the lower array number of Wordlist
        'UBound is the upper arra number of Wordlist
        For i = LBound(WordList) To UBound(WordList)
            str1stChar = WordList(i).Substring(0, 1)
            Select Case str1stChar.ToUpper
                Case "A", "E", "I", "O", "U"
                    strOutput = (strInput & "WAY")
                Case Else
                    strOutput = (WordList(i).Substring(1) & str1stChar & "AY")
            End Select
            'Now since we have seperated each word
            'we have to put it back together... and put spaces back between...
            strTotalOutput = strTotalOutput + strOutput + " "

            'Loop through each word...
        Next i

        MessageBox.Show(strTotalOutput, "Pig Latin")


This post has been edited by cardswin12: 22 Feb, 2008 - 07:07 AM
User is offlineProfile CardPM
+Quote Post

cardswin12
RE: Pig Latin More Than One Word
25 Feb, 2008 - 06:45 AM
Post #8

New D.I.C Head
*

Joined: 14 Feb, 2008
Posts: 9

For some reason, when a word starts with a vowel, the program messes up, but when a word starts with consanents it works.
User is offlineProfile CardPM
+Quote Post

LookNAO
RE: Pig Latin More Than One Word
25 Feb, 2008 - 09:34 AM
Post #9

D.I.C Head
**

Joined: 28 Dec, 2007
Posts: 66



Thanked: 1 times
My Contributions
CODE

Dim str1stChar, strInput As String
        strInput = txtInput.Text
        str1stChar = txtInput.Text.Substring(0, 1)
        Dim strOutput As String = ""

        Dim WordList As String()  'This makes an uninitialised array

        WordList = Split(strInput, " ")   'this splits up the text into an array of words.

        Dim i As Integer
        Dim strTotalOutput As String

        'LBound is the lower array number of Wordlist
        'UBound is the upper arra number of Wordlist
        For i = LBound(WordList) To UBound(WordList)
            str1stChar = WordList(i).Substring(0, 1)
            Select Case str1stChar.ToUpper
                Case "A", "E", "I", "O", "U"
                    strOutput = (WordList(i) & "WAY")  <-----------------------The fix
                Case Else
                    strOutput = (WordList(i).Substring(1) & str1stChar & "AY")
            End Select
            'Now since we have seperated each word
            'we have to put it back together... and put spaces back between...
            strTotalOutput = strTotalOutput + strOutput + " "

            'Loop through each word...
        Next i

        MessageBox.Show(strTotalOutput, "Pig Latin")


User is offlineProfile CardPM
+Quote Post

Nayana
RE: Pig Latin More Than One Word
25 Feb, 2008 - 11:32 PM
Post #10

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
OK, the above code should work.

However, I don't like all the strTotalOutput = strTotalOutput + strOutput + " ". It would be better to use Join(String()) which is the opposite of Split(String). Here is my modified code for the loop.

vb

For i = LBound(WordList) To UBound(WordList)
str1stChar = WordList(i).Substring(0, 1)
Select Case str1stChar.ToUpper
Case "A", "E", "I", "O", "U"
WordList(i) = (WordList(i) & "WAY") <-----------------------The fix
Case Else
WordList(i) = (WordList(i).Substring(1) & str1stChar & "AY")
End Select

'Loop through each word...
Next i

'Now, since we have separated each word
'we have to put it back together with spaces.
strTotalOutput = String.Join(" ", WordList)


This post has been edited by Nayana: 26 Feb, 2008 - 12:34 AM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Pig Latin More Than One Word
25 Feb, 2008 - 11:35 PM
Post #11

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,478



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to VB.Net smile.gif

Wow, thats a lot of legacy libraries being used in VB.Net crazy.gif
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 02:50PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month