get first n characters from string

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

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:




to get the first 4 characters, or “Hell”.

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

:bust_in_silhouette: Reply From: Diet Estus

There is talk of this being added in Godot 3.1.

See Array slicing for GDScript · Issue #4715 · godotengine/godot · GitHub for discussion as well as workarounds.

:bust_in_silhouette: Reply From: Gerardo Gonzalez

Like this:


Here the full String Class Doc :smiley:

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

ramazan | 2021-09-11 12:50

string = string.left(4)

sterngames | 2022-08-21 16:16

sorry, incorrect. please ignore.

sterngames | 2022-08-22 10:21

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 :)))

ramazan | 2022-08-23 09:27

? i don’t understand what you’re saying

sterngames | 2022-08-23 09:33

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

ramazan | 2022-08-23 10:23