Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    String slice hard crash

    Bug Reporting (FUZE 4 Nintendo Switch)
    2
    3
    224
    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.
    • Z-Mann
      Z-Mann last edited by

      Executing the following code crashes FUZE hard (termniate to the system menu):

      s = "Hello World!"
      f = s[0:len(s)-2]
      

      Workaround: Store the length in an intermediate variable:

      s = "Hello World!"
      l = len(s)
      f = s[0:l-2]
      

      What bothers me more than the crash is that, to cut off the last character of a string, I have to use l-2, not l-1. That does not seem to fit with the index range philosophy in other places (array index goes from 0 to len(array)-1, for i = 0 to 10 goes from 0 to 9) and makes it impossible to get a zero length slice; s[0:0] is still one character. String and array slices are undocumented AFAIK, so you can still change that and nobody would have the right to complain if you break their code :)

      1 Reply Last reply Reply Quote 0
      • Z-Mann
        Z-Mann last edited by

        Oh, turns out
        f = s[0:-2]
        also works perfectly and returns s with the last character removed, no need to call len() at all. Still, gnarl, -2 instead of -1....

        1 Reply Last reply Reply Quote 0
        • Dave
          Dave Fuze Team last edited by

          @Z-Mann apologies for the delayed response. We will look into it.

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