+2 votes

In gdscript, I know that I can get a character from a specific location using something like this:

var string = "Hello"
print(string[3])        # prints "l"

In python, we can use:

string[0:3]

or

string[:3]

to get the first 4 characters, or "Hell".

Is there a way to do this on gdscript as well?

in Engine by (20 points)

2 Answers

0 votes

There is talk of this being added in Godot 3.1.

See https://github.com/godotengine/godot/issues/4715 for discussion as well as workarounds.

by (1,581 points)
+1 vote

Like this:

print("Hello".left(4))

Here the full String Class Doc :-D http://docs.godotengine.org/en/3.0/classes/class_string.html?highlight=String#class-string-left

by (182 points)

I've been looking for this for almost 2-3 hours. :))
so how do we delete the first 4

string = string.left(4)

sorry, incorrect. please ignore.

I asked myself while reading this. I had some alcohol yesterday. What did you do last night, I said to myself. Then looking at history :)))

? i don't understand what you're saying

nevermind. I use google translation. English is not my native language

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.