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?
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()
Re: PDA PigLatin application
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
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