M
Mythran
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
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