How do I get a substring of characaters that only returns form start to finish with values I give it.

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

So I have a list with a few strings:

list = ["This is a test string", "Please help me, I'm lost"]

I want to get a portion of the string 0. For example, I want to get the substring “test”.

I tried using the method substr() but when I give the parameters it returns the previous substrings aswell.

list[0].substr(9, 14)

Returns: “This is a test” And I only want “test”

Is this possible?

:bust_in_silhouette: Reply From: Legorel

From the godot documentation: String — Godot Engine (stable) documentation in English

String substr ( int from, int len=-1 )

Returns part of the string from the position from with length len. Argument len is optional and using -1 will return remaining characters from given position.

This means you need to to

list[0].substr(10, 4)

to get only the word “test”