|
-
Jan 13th, 2006, 01:30 PM
#1
Thread Starter
Junior Member
PDA PigLatin application
I want to make a PDA application that converts english to pig latin. this is what i have but I am getting errors. Can anyone help me?
VB Code:
Private Sub cmdEngToPigLatin_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEngToPigLatin.Click
Dim s As Object
Dim Strings_Renamed As Object
Strings_Renamed = Split(txtInput.Text, " ")
For s = 0 To UBound(Strings_Renamed)
Strings_Renamed(s) = VB.Right(Strings_Renamed(s), Len(Strings_Renamed(s)) - 1) & VB.Left(Strings_Renamed(s), 1) & "ay"
Next
MessageBox.Show(Replace(Join(Strings_Renamed, " "), vbCrLf, ""), "Pig Latin")
txtInput.Text = ""
txtInput.Focus()
End Sub
-
Jan 13th, 2006, 01:52 PM
#2
Re: PDA PigLatin application
You should probably use a string array instead of an object.
VB Code:
Dim Strings_Renamed() As String
I'd dim a string output and add each updated word to it, then you wouldn't need to worry about joining the array.
What errors are you getting and on which line?
TPM
Add yourself to the VBForums Frappr Map!!
-
Jan 13th, 2006, 01:59 PM
#3
Re: PDA PigLatin application
this is my opinion but you should also think about starting to get away from old VB ways.
look at the following...
VB Code:
Dim Strings_Renamed As String()
Strings_Renamed = Me.txtInput.Text.Split(" "c) ' Split(txtInput.Text, " ")
For i As Integer = 0 To Strings_Renamed.Length - 1
Strings_Renamed(i) = Microsoft.VisualBasic.Right(Strings_Renamed(i), Strings_Renamed(i).Length - 1) + _
Microsoft.VisualBasic.Left(Strings_Renamed(i), 1) + "ay"
'microsoft.VisualBasic.Right(
'Strings_Renamed(s) = VB.Right(Strings_Renamed(s), Len(Strings_Renamed(s)) - 1) & _
' VB.Left(Strings_Renamed(s), 1) & "ay"
Next
MessageBox.Show(String.Join(" "c, Strings_Renamed).Replace(vbCrLf, ""), "Pig Latin")
'MessageBox.Show(Replace(Join(Strings_Renamed, " "), vbCrLf, ""), "Pig Latin")
txtInput.Text = ""
txtInput.Focus()
-
Jan 13th, 2006, 02:05 PM
#4
Thread Starter
Junior Member
Re: PDA PigLatin application
-
Jan 13th, 2006, 02:19 PM
#5
Re: PDA PigLatin application
I love pig Latin, so I decided to add a few things to your idea.
One, I think it's best to compartmentize the logic. Have one function to perform it on a single word, and another to do it to a string. Also, Pig lation doesn't take just the first letter, it's everything before the first vowel (for example "There" = "erethay".
VB Code:
Private Function ConvertStringToPig(ByVal str As String) As String
Dim strarray As String() = str.Split(" ")
If strarray.Length < 2 Then Return Eng2Pig(str) 'Handles one word strings.
Dim workstring As String = ""
For Each strvar As String In strarray
workstring += Eng2Pig(strvar) + " "
Next
workstring = workstring.Substring(0, workstring.Length - 1) 'Kill the last space.
Return (workstring)
End Function
Private Function Eng2Pig(ByVal str As String) As String
Dim Vowels As String = "aeiouAEIOUyY"
Dim positionToSplit As Integer = str.IndexOfAny(Vowels)
If positionToSplit <> -1 Then 'YOu split on the first vowel, not always the second char.
Return (str.Substring(positionToSplit) + str.Substring(0, positionToSplit) + "ay")
Else : Return str
End If
End Function
Of course, this still doesn't fix the problem with capital letters, but that should be easy enough to fix..
Bill
-
Jan 13th, 2006, 06:31 PM
#6
Re: PDA PigLatin application
I tweaked him a little too
VB Code:
'Option Strict On
Private Function ConvertStringToPig(ByVal str As String) As String
Dim strarray As String() = str.Split(" "c)
If strarray.Length < 2 Then Return Eng2Pig(str) 'Handles one word strings.
Dim workstring As String = ""
For Each strvar As String In strarray
workstring += Eng2Pig(strvar) + " "
Next
Return (workstring.TrimEnd) 'Kill the last space.
End Function
Private Function Eng2Pig(ByVal str As String) As String
Dim Vowels() As Char = "aeiouAEIOUyY".ToCharArray
Dim SpecialChars() As Char = ("`1234567890-=~!@#$%^&*()_+<>?,./;[]\|}{:""").ToCharArray
'Handle Punctuation and special characters
Dim Excludestring As String
Dim positionToSplit As Integer = str.IndexOfAny(SpecialChars)
If str.IndexOfAny(SpecialChars) >= 0 Then
Excludestring = str.Substring(positionToSplit)
str = str.Substring(0, positionToSplit)
End If
positionToSplit = str.IndexOfAny(Vowels)
If positionToSplit <> -1 Then 'YOu split on the first vowel, not always the second char.
str = (str.Substring(positionToSplit, 1).ToUpper + str.Substring(positionToSplit + 1) + str.Substring(0, positionToSplit).ToLower + "ay")
End If
Return str & Excludestring
End Function
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
|
Click Here to Expand Forum to Full Width
|