0 votes

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?

Godot version 3.2.1
in Engine by (12 points)

1 Answer

+2 votes

From the godot documentation: https://docs.godotengine.org/en/stable/classes/class_string.html#class-string-method-substr

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"

by (272 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.
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 webmaster@godotengine.org with your username.