[OT] Plurlize() Method
- From: "Mythran" <kip_potter@xxxxxxxxxxx>
- Date: Mon, 2 Feb 2009 08:57:47 -0800
This is off-topic slightly and not language dependant. But still, I would like some pointers or suggestions regarding a pluralize method. I have a method which accepts a string and I have it returning the plural form of the specified string (where the specified string is a single word or word combination). I know these types of methods won't work 100% of the time, but a good majority of the words should work.
Any suggestions or pointers on if I'm missing anything to the following logic would be appreciated:
If the word is null or empty, return the word (null or empty).
If the length of the word is 1 character, return the character + "s".
If the entire word is upper-case:
If the word ends in an "s", return the word + "S".
If the word ends in "is", remove the "is" and return the remaining portion of the word + "es".
If the word ends with "s", "z", "x", "ch", or "sh", return the word + "es".
If the word ends in "y":
If the word ends with an "ay", "ey", "iy", "oy", or "uy", return the word + "s".
Otherwise, remove the last character and return the remaining word + "ies".
Last case scenario, if the above conditions do NOT match the specified word, return the word + "s".
Thanks,
Mythran
.
- Follow-Ups:
- Re: [OT] Plurlize() Method
- From: Peter Morris
- Re: [OT] Plurlize() Method
- From: Family Tree Mike
- Re: [OT] Plurlize() Method
- From: Jeroen Mostert
- Re: [OT] Plurlize() Method
- From: Göran Andersson
- Re: [OT] Plurlize() Method
- From: Jeff Johnson
- Re: [OT] Plurlize() Method
- Prev by Date: Re: c# call virtual/abstruct function from the constructor of the base class
- Next by Date: Re: polling an intranet for a device type
- Previous by thread: c# call virtual/abstruct function from the constructor of the base class
- Next by thread: Re: [OT] Plurlize() Method
- Index(es):
Relevant Pages
|