For some reason, I can't seem to remove spaces from a string.
I've tried the following:

var place: String = "placeholder place2"

place.replace(" ", "")

place.dedent()

place.format({" ": ""})

And none of these worked. They all still had the space. How can I remove it?

  • Zini replied to this.

    Zini According to the documentation, there should be nothing stopping it from replacing the space (" ") with nothing (""), and yet it isn't.

      • Edited

      NovaSE Similar to Python, GDScript strings are immutable. You can't alter a string in-place. All string functions that seemingly change the string, in fact return a new altered string. So you need to re-assign the returned value, exactly like in that example line posted by @Zini

      NovaSE there should be nothing stopping it from replacing the space

      It is replacing the space. You can verify that:

      print("before: ", place)
      print("after: ", place.replace(" ", ""))

      But you're not saving the result.

      It's like going grocery shopping, placing items in your cart, and then walking out of the store without the groceries.