+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?

asked May 21, 2018 in Engine by jsyune1213 (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.

answered May 21, 2018 by Diet Estus (1,504 points)
0 votes

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

answered May 21, 2018 by Gerardo Gonzalez (142 points)
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 How to use this Q&A? before posting your first questions.