tags:

views:

80

answers:

1

in ruby on rails,this is plural and singular functions added to ruby String class.

how can i implements plural and singular functions in java?

such as "book" plural() => "books" "books" singular => "book"

+4  A: 

Assuming you want to cover the exception cases too (e.g. person => people) then the module that handles this in Ruby on Rails is called Inflector. Take a look at this Inflector project on java.net for something similar in Java. From the project summary:

Inflector is a Java API for forming plurals of words. The library supports English spellings, and is locale-aware so it is straightforward to customize for any language.

Note: that I think this might only do singular => plural and not the other way around.

mikej
If I remember correctly, that was the best answer given to the previous question I mentioned. +1. :)
Carl Smotricz
Thank you It is very nice of you I get another methodthe url is http://www.oschina.net/bbs/thread/104be concerned with the code onlyi hope you can understand Chinesehaha
wangxl