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?
Example:
"book"  plural() => "books"
"books"  singular  =>  "book"
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.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论