Substr method for godot does not split properly

Godot Version

godot 4.0

Question

I’m trying to implement a function that take a string as input, detect certain words and split them in respective parts. here is my code:

		character = text.substr(0, text.find(":")+1)
		dialogue = text.substr(text.find(":") + 1, text.find(" split:"))
		command = text.substr(text.find(" split:"))

the code is expected to process the string:
“test:this is an example split: randomstuff”
into “test:”, “this is an example”, " split: random stuff" (there is a space bar in the last string)
however, it does this:
image
this is very confusing and I must have made a silly mistake in 3 lines of code. the first and last part of the splitted string work as expected but for the middle section(dialogue) the split isn’t done properly. Whats even worse is that there isn’t even a pattern for how much of the “split” is not done properly meaning its unlikely to just be an error on index.
Please tell me whats the problem and how to fix it.

2nd param must subtract length of 1st param. 2nd param is length and not up to.

thank you so much! I thought its the same as python

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.