Programming with Microsoft Visual Basic Pig Latin


This article is written by Pon Saravanan  on 10-Sep-09 Last modified on :10-Sep-09





Pig Latin Visual Basic Sample

Pig Latin is a game which is played by children. Usually to make an impression that, we are speaking in different language. While there are various ways to create pig Latin from English. I just took some simple way to explain how to use string functions. So if something missing related to Pig Latin game, I may not modify, as my intention of this program is to explain string related functions  


Source Code

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
  
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Add(PigLatin("beast") )
        ListBox1.Items.Add(PigLatin("dough"))
        ListBox1.Items.Add(PigLatin("happy"))
        ListBox1.Items.Add(PigLatin("question")) 'consonant rule is not applied
        ListBox1.Items.Add(PigLatin("star"))
        ListBox1.Items.Add(PigLatin("three"))
        ListBox1.Items.Add(PigLatin("alarm"))
    End Sub
    Public Function PigLatin(ByVal InputEnglishWord As String) As String
        Dim PigLatinWord As String
        Dim Consonant() As String = New String() {"a", "e", "i", "o", "u"}
        Dim IndexToShufle As Integer = GetFirstVowelLocation(InputEnglishWord)
        If (IndexToShufle = 0) Then 'starts with vowel
            PigLatinWord = InputEnglishWord & "-yay"
        Else
            If (IndexToShufle = -1) Then IndexToShufle = 1
            PigLatinWord = InputEnglishWord.Remove(0, IndexToShufle) & "-" & InputEnglishWord.Substring(0, IndexToShufle) & "ay"
        End If

        Return PigLatinWord
    End Function
    Public Function GetFirstVowelLocation(ByVal InputEnglishWord As String) As Integer
        Dim Vowels() As String = New String() {"a", "e", "i", "o", "u"}
        Dim LastLocation As Integer
        LastLocation = InputEnglishWord.Length
        For Each Letter In Vowels
            Dim CurrentLocation As Integer = InputEnglishWord.IndexOf(Letter, 0)
            If (CurrentLocation <> -1 And CurrentLocation < LastLocation) Then
                LastLocation = InputEnglishWord.IndexOf(Letter, 0)
            End If
        Next
        If (LastLocation = InputEnglishWord.Length) Then LastLocation = -1
        Return LastLocation
    End Function
End Class











Comments
  • GUEST
    d 11/29/2010 7:02:11 AM

  • GUEST
    12/14/2010 12:02:48 AM

  • GUEST
    6/7/2011 12:42:25 AM


Comments
   
Captcha Image
For you specially:  
Captcha Text Enter the text in the image.(Not Case sensitive)    



Spam Bot Trap



   



Select Theme
White
Blue
Brown
Gray