Skip to content

Instantly share code, notes, and snippets.

@davebrny
Last active November 14, 2017 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davebrny/7cab642728f25ca5cad2b9611582a284 to your computer and use it in GitHub Desktop.
Save davebrny/7cab642728f25ca5cad2b9611582a284 to your computer and use it in GitHub Desktop.
(autohotkey) - return or add a singular/plural suffix
sp(number, string="", suffix="s") {
if (string)
string := number " " string
if (number = 1)
return string . ""
else return string . suffix
}
@davebrny
Copy link
Author

davebrny commented Nov 13, 2017

examples:

folders = 1
files   = 4
msgBox, % " folder" sp(folders) " and file" sp(files)
watches = 2
msgBox, % " watch" sp(watches, , "es")
potatoes = 3
plates   = 2
msgBox, % sp(potatoes, "potato", "es") . " and " . sp(plates, "plate")

 

ternary example:   (number=1?"":"s")

number = 3
msgBox, % "variable" . (number = 1 ? "" : "s")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment