How can convert string to number?

Not favoritedFavorited Favorited 0 favourites
  • 7 posts
From the Asset Store
A collection of a mix of percussion and orchestral string loops, including 20 musical sketches.
  • Hey guys i'm trying to parse layout name as number and can't find the correct expression for this. When I do int(LayoutName) it always returns 0 thought my layout name is "L11". I'm thinking to use the js junction parseInt instead but i don't really like this solution cause this exact project I do with blocks. Maybe you how know to do that without coding?

  • Likely int() uses parseInt() under the hood so it would still return 0. The string would need to start with a number for int() to work.

    If your layout makes have the pattern of a letter then a number then you could do int(mid(layoutname,1,10)) or something.

  • 	RegexMatchAt(LayoutName,"\d+","g",0)
    

    That gives you the first number in the LayoutName.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Likely int() uses parseInt() under the hood so it would still return 0. The string would need to start with a number for int() to work.

    If your layout makes have the pattern of a letter then a number then you could do int(mid(layoutname,1,10)) or something.

    Yeah, you are right. I forgot that it parse correct only if first symbol is number. Looks like i need something like regex or I will try your solution. Thanks

    UPD: It works perfectly. Thanks

  • > 	RegexMatchAt(LayoutName,"\d+","g",0)
    

    That gives you the first number in the LayoutName.

    Thanks, I will try

  • Just provide another idea.

    You can use a delimiter to separate it.

    like: Layout-1, Layout-20

    Then use tokenat expression to get out the number.

    tokenat(LayoutName, 1, "-")
    

    For example:

    tokenat("Layout-5", 1, "-") // 5
    tokenat("Layout 5", 1, " ") // you can also use spaces as delimiters.
    
  • Just provide another idea.

    You can use a delimiter to separate it.

    like: Layout-1, Layout-20

    Then use tokenat expression to get out the number.

    > tokenat(LayoutName, 1, "-")
    

    For example:

    > tokenat("Layout-5", 1, "-") // 5
    tokenat("Layout 5", 1, " ") // you can also use spaces as delimiters.
    

    Thank you. I will try

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)