How to remove the square brackets from array to string?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By OiKeTTLe

As the title suggests, I’m setting a label’s text to the string of an array. The issue is, it includes the brackets in said array. Any fixes? In addition, if anyone is willing to help, how can I convert this array to a list instead?

:bust_in_silhouette: Reply From: Gluon

You can do something like this

var array = ["1", "2", "3"]
var st = ""
for i in array:
	st = st + str(i)
print(st) 

to iterate over an array and add it to a string

Is there any shorter way to do that?

Shorter than these few lines of code? Why would you need that to be any shorter? Are you playing Code Golf?

1 Like

Its cuz its ONE SIMPLE THING that for some reason isnt just a array attribute (idk whats it name)

I don’t think you can make it even shorter, The only thing you can do is make your own function and make it global soo you can access it from anywhere in the script

ooo good idea

cool,please don’t be rude in this forum

okay!

(pretend thats not there godot forces me to make it more than 6 letters)

Have you seen C++(the core language Godot is written in?)

It takes around 125+ characters to do it in c++… soo be happy what you have.

2 Likes

print(“, “.join(yourarray))

That’s some EPIK code golfing