Quick coding question: Is there a way to check if a variable is a string?
-
I see there is a method to check if a variable is an array, but I don't see something similar to check if a variable is a string.
Is there a method for that?
If not, is there a method to check if a variable is an integer?
I would like to make an inline function that can accept either an integer or a string as one of the arguments, but they need separate handling inside the inline function. -
typeof(myVar) == "string"
@VirtualVirgin said in Quick coding question: Is there a way to check if a variable is a string?:
I would like to make an inline function that can accept either an integer or a string as one of the arguments,
I would try to avoid this. I've started using the type safety stuff in HISE for everything lately and it prevents lots of little type related bugs I used to run into, before they can happen. But to use it you need to allow only one data type possibility per parameter/return value.
If you want to have one or the other I would create two functions, or turn your strings into numbers with parseInt/parseFloat.