Generate a string with n 1's

0 favourites
  • 5 posts
  • Say I want to generate a string 111...1 (say 100 1's). I can do it with a for loop, just wondering if there is any simple expression to do that instead. Thanks.

  • You can do this:

    Variable s= "111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    1111111111111111111111111111111111111111111111111111111111111111111111111111111111111"

    Set text to left(s, 100)

    But it's better to use a loop:

    Repeat 100 times : Set s to (s & "1")

  • In the system expressions

    MyVar = zeropad(1,99)

    Replace(MyVar, 0,1)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In the system expressions

    MyVar = zeropad(1,99)

    Replace(MyVar, 0,1)

    Thanks!

  • repeat 100 times

    set s = s & 1

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