By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,830 Members | 658 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,830 IT Pros & Developers. It's quick & easy.

Appending an s for plural

P: n/a
I posted this from work but I don't think it got through so apologies if
this is duplicated.

I'm trying to avoid the old chestnut where you go something like:

Span = lngDays & " day(s)"

so that an s gets appended only if it's more than 1, I came up with this:

Span = lngDays & " day" & String(Abs(Sgn(lngDays - 1)), "s")

which seems to take care of minus numbers and makes 0 a plural, just
wondering if anyone's got a neater solution.
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I use the IIf() function:

Span = lngDays & " day" & IIf(Abs(lndDays)<>1,"s", "")

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQSO0BIechKqOuFEgEQK3+QCfdSYuRvMAbYPv0GMpdj8MJC zjd7QAoM5z
wSvPwgrxZINrSWNn5EaF1iEg
=rdnD
-----END PGP SIGNATURE-----
Trevor Best wrote:
I posted this from work but I don't think it got through so apologies if
this is duplicated.

I'm trying to avoid the old chestnut where you go something like:

Span = lngDays & " day(s)"

so that an s gets appended only if it's more than 1, I came up with this:

Span = lngDays & " day" & String(Abs(Sgn(lngDays - 1)), "s")

which seems to take care of minus numbers and makes 0 a plural, just
wondering if anyone's got a neater solution.


Nov 13 '05 #2

P: n/a
Trevor Best escreveu:
I posted this from work but I don't think it got through so apologies if
this is duplicated.

I'm trying to avoid the old chestnut where you go something like:

Span = lngDays & " day(s)"

so that an s gets appended only if it's more than 1, I came up with this:

Span = lngDays & " day" & String(Abs(Sgn(lngDays - 1)), "s")

which seems to take care of minus numbers and makes 0 a plural, just
wondering if anyone's got a neater solution.


Maybe a trickiest (?) way:

Span = lngDays & " day" & String(-(Abs(lngDays) <> 1), "s")

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.