This is a short function for determining whether your string starts with a vowel or a consonant.
I recently had a usecase for this when working on some text generation and thought I would publish a simple function on here for free use, incase someone else would find it of use here.
local function FirstIsVowel(str)
return str:match("^[AEIOUaeiou]") and true -- cast to bool
end
Example use :
if FirstIsVowel(Fruit) == true then
print("There is an" .. Fruit) -- The first letter in the string is a vowel
else
print ("There is a" .. Fruit) -- The first lettter in the string is a consonant
end
Here, Banana starts with a consonant and thus gets the output āThere is a Bananaā, Apple on the other starts with a vowel and gets the output āThere is an Appleā.