# VBForums CodeBank > CodeBank - Other >  Easy Pluralization

## minitech

It's always annoying to spend time working with ternary if statements and what not, or even (gasp) using a variable to pluralize things. Here's a snippet that makes it easier.

http://jsfiddle.net/minitech/PefYd/

You use it like so:


```
var str = "There {is|are} # apples. The #&#37; apple looks nice to me.".plural(5);
```

Which gives:



```
"There are 5 apples. The 5th apple looks nice to me."
```

# is replaced with the passed integer. % becomes st, nd, rd, or th. {_x_} becomes _x_ if the number is plural, nothing otherwise. {_x_|_y_} becomes _x_ if the number is singular, _y_ if it is plural. More than 2 results in 1 being turned into the first one, 2 to the second one, 3 to the third one, etc. and all out of range values being turned into the last one.

Enjoy! Suggestions are welcome.

----------


## techgnome

Haven't looked at the code... but might need some more work as "There are 1 apples. The 1st apple looks nice to me." doesn't work either... specifically "There are 1 apples." ??? Even "There is 1 apples." doesn't work. I'm just saying. :P

Would it need to be done like this?
var str = "There {is|are} # {apple|apples}. The #&#37; apple looks nice to me.".plural(1);
Would it work at that point? 
I will admit... that's pretty cool... 

-tg

----------


## minitech

Oops, it's supposed to be apple{s} instead. Sorry.

----------


## Hack

In what kind of program would I use this?

----------


## minitech

In any sort of page where you need pluralization. For example, on websites (like SourceForge) that say "Your download will start in 1 seconds". Using this, the "seconds" can turn into "second" at the right time.

----------

