HISE Logo Forum
    • Categories
    • Register
    • Login

    Quick coding question: Is there a way to check if a variable is a string?

    Scheduled Pinned Locked Moved Scripting
    2 Posts 2 Posters 42 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • VirtualVirginV
      VirtualVirgin
      last edited by

      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.

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @VirtualVirgin
        last edited by d.healey

        @VirtualVirgin

        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.

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        1 Reply Last reply Reply Quote 0
        • First post
          Last post

        45

        Online

        1.7k

        Users

        11.7k

        Topics

        102.1k

        Posts