Android Question Convert user text entry from singular to plural?

U

unba1300

Guest
Hi. I have the following code which converts text entered by the user from a singular context to a plural context:
Code: Copy
            If et.Contains("his ") Then et = et.Replace("his ", "their ")
            Words = Regex.Split(" ", et)
            If Words.Length > 1 Then
                For i = 0 To Words.Length - 1
                    If Words(i) = "their" Then
                        ToPlural = Words(i + 1)
                        If ToPlural.EndsWith("ey") Then
                            ToPlural = ToPlural.SubString2(0, ToPlural.Length -2)
                            et = et.Replace(ToPlural, ToPlural & "ies")
                        Else If ToPlural.EndsWith("ny") Then
                            ToPlural = ToPlural.SubString2(0, ToPlural.Length -1)
                            et = et.Replace(Words(i + 1), ToPlural & "ies")
                        Else If ToPlural.EndsWith("ry") Then
                            ToPlural = ToPlural.SubString2(0, ToPlural.Length -1)
                            et = et.Replace(Words(i + 1), ToPlural & "ies")
                        Else If ToPlural.EndsWith("is") OR _
                            ToPlural.EndsWith("tch") Then
                            et = et.Replace(ToPlural, ToPlural & "es")
                        Else If ToPlural.EndsWith("s") OR _
                            ToPlural.EndsWith("th") Then
                            'Don't change the ending.
                        Else
                            et = et.Replace(ToPlural, ToPlural & "s")
                        End If
                    End If
                Next
             End If
This works well for changing text like "raised his arm" to "raised their arms", but if the original is "raised his left arm" it gets changed to "raised their lefts arm". Do you know how I could change this code to make the last word plural instead? Thanks.
 
Back
Top