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