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.


13 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.

  8. =IF(RIGHT(B16,2)="is",LEFT(B16,LEN(B16)-2)&"es",IF(RIGHT(B16,2)="us",LEFT(B16,LEN(B16)-2)&"i",IF(OR(RIGHT(B16,2)="ss",RIGHT(B16,2)="ch",RIGHT(B16,2)="sh"),B16&"es",IF(RIGHT(B16,2)="fe",LEFT(B16,LEN(B16)-2)&"ves",IF(OR(RIGHT(B16,1)="s",RIGHT(B16,1)="o",RIGHT(B16,1)="x",RIGHT(B16,1)="z"),B16&"es",IF(RIGHT(B16,1)="y",LEFT(B16,LEN(B16)-1)&"ies",IF(RIGHT(B16,1)="f",LEFT(B16,LEN(B16)-1)&"ves",IF(RIGHT(B16,2)="on",LEFT(B16,LEN(B16)-2)&"a",B16&"s"))))))))

  9. abc formula didn’t work until I replaced the quotation marks. It works great now except for words that are plural already. It also does not wok great with irregular nouns.

  10. WordPress like to make quote marks fancy. I put <code> tags around it to fix the quote marks

Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.