Make Plural

As part of “class module week”, I need a function that takes a class module name and makes it plural. I’d like to catch more than 95% of standard nouns and throw in a few non-standard ones for good measure. Here’s what I have so far.

Function MakePlural(sWord As String) As String

Select Case sWord
Case "CPerson"
MakePlural = "CPeople"
Case "CChild"
MakePlural = "CChildren"
Case "CDatum"
MakePlural = "CData"
Case "CAlumnus"
MakePlural = "CAlumni"
Case "CCriterion"
MakePlural = "CCriteria"
Case "CMedium"
MakePlural = "CMedia"
Case Else
If Right$(sWord, 2) Like "[a,e,i,o,u]y" Then
MakePlural = sWord & "s"
ElseIf Right$(sWord, 2) = "is" Then
MakePlural = Left$(sWord, Len(sWord) - 2) & "es"
ElseIf Right$(sWord, 1) = "y" Then
MakePlural = Left$(sWord, Len(sWord) - 1) & "ies"
ElseIf Right$(sWord, 1) = "f" Then
MakePlural = Left$(sWord, Len(sWord) - 1) & "ves"
ElseIf Right$(sWord, 2) = "ss" Or Right$(sWord, 1) = "x" Then
MakePlural = sWord & "es"
Else
MakePlural = sWord & "s"
End If
End Select

End Function

Thoughts?

10 thoughts on “Make Plural

  1. Radius vs. Radii

    And what about words that don’t change when plural?
    “Moose” “Deer” “Aircraft” “Water”

  2. You missed some that do a quirky change, like: mouse -> mice, goose -> geese, man -> men, woman -> women, tooth -> teeth.

    Then there are the ones that don’t change at all, like: deer, fish, sheep.

    But c’mon. How likely are you to have a class module called “CSheep”? :-)

  3. And what happens if an already plural word is passed in. There is no check for that. Fun exercise.

  4. Scott: I definitely left out some irregulars that would *never* be classes – at least in any apps I’m going to write.

    Shawn: I guess I can’t read Ruby, because I could not make heads or tails of it. I didn’t see any real string manipulation, just further calls to pluralize.

    Ron: If you pass in a plural, e.g. Jobs, you get Jobss. I don’t think I would change that behavior. Should I?

  5. I would think an error should be returned or return the original word since you can’t pluralize a plural. But I may be over-complicating the exercise.

  6. You could capture most cases, then leave it as an exercise for the end-user for the remainder, storing singular/plural matches as you go, so they only need to do it once.

    Also: found some examples googled ‘code to pluralize’

  7. Here’s one in PHP, see the source code link below the form.

    It seems to have a lengthy list of specific cases, and makes good use of regular expressions.

Leave a Reply

Your email address will not be published. Required fields are marked *