Plural procedure for text

Share your advanced PureBasic knowledge/code with the community.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Plural procedure for text

Post by PB »

Code updated For 5.20+

I needed this for describing the number of items with the correct plural, as
I was tired of always testing if the item count was 1 or not, and I also hate
how apps say 1 item(s) with the (s) part for only 1 item. :roll:

Code: Select all

; Plural by PB.

Procedure.s Plural(num,text$)
  a$=Str(num)+" "+text$ : If num<>1 : a$+"s" : EndIf
  ProcedureReturn a$
EndProcedure

a=Random(2) : b=Random(2) : Debug "I ate "+Plural(a,"apple")+" and "+Plural(b,"banana")+"."
f=Random(2) : Debug "You have "+Plural(f,"file")+" selected."
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Eheheh doesn't work in portuguese ;)

But it's a linguistic problem, not a code problem!

LOL
Fred
Administrator
Administrator
Posts: 18252
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Also in french, you will have to do a bunch of exceptions ;).
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

Hmm you should fix this Fred, I will give you 8 hours then I will hav to write a classtest on it and I hate that french is not like pb^^
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Hey, don't feel bad, once you get it working in French, Portuguese is easy!

Our grammar is alike!
Post Reply