It would be great if I could create a method that counts the number of variables that contain a desired string.
Let’s say the string is “hi”, and the method needs to take in any number of variables, I’ll be entering 2 or more.
Variables:
var1 = "hi"
var2 = "bye"
var3 = "hi"
result = countvariables("hi",var1,var2,var3)
Here I have put the desired string in the variable parameters, however it can also be entered when the method is created.
Result should contain the number 2. Because 2 variables contain the string “hi”.
Is this possible?
1 Answer