Godot: String.rsplit and String.split are the same

Created on 3 Jun 2019  路  10Comments  路  Source: godotengine/godot

Maybe i am just misunderstanding but this is what i expected and what i'v got instead:
var updates : String = "path/morePath/file.exe"
Both print(updates.rsplit("/")) and print(updates.split("/")) returns ["path","morePath","file.exe"] while i would expect print(updates.rsplit("/")) to return ["file.exe","morePath","path"]. Even in the documentation it states that the result is the same. If so, then whats the difference between them?

PoolStringArray split ( String divisor, bool allow_empty=True, int maxsplit=0 )
Splits the string by a divisor string and returns an array of the substrings.

Example: "One,Two,Three" will return ["One","Two","Three"] if split by ",".

If maxsplit is given, at most maxsplit number of splits occur, and the remainder of the string is returned as the final element of the list (thus, the list will have at most maxsplit+1 elements)

PoolStringArray rsplit ( String divisor, bool allow_empty=True, int maxsplit=0 )
Splits the string by a divisor string and returns an array of the substrings, starting from right.

Example: "One,Two,Three" will return ["One","Two","Three"] if split by ",".

If maxsplit is specified, then it is number of splits to do, default is 0 which splits all the items.

documentation enhancement junior job

Most helpful comment

All 10 comments

The last argument makes difference. If you specify max splits, you will end up with n strings either starting from left or from right.

Well since i opened this,
"Splits the string by a divisor string and returns an array of the substrings."
That's partly wrong, it returns a PoolStringArray, not an Array. Or is it the same? when i tried myArray.back() it said nonexistent method in class.

PoolStringArray is a type of array (lowercase, common noun designing a list container), but not an Array indeed (capitalized, formatted as code, builtin class name). So it's fine to refer to it as "an array" and the PoolStringArray return type specified in the signature tells you what kind of array exactly.

The documentation could be improved to make things clearer though. If the only difference comes from the maxsplits argument, the code example should make use of it to show this difference. It should also be clearer that the string is split from the right up to maxsplits, but that the returned split strings are still ordered from left (maxsplits-th split) to right (0).

PoolStringArray is a type of _array_ (lowercase, common noun designing a list container), but not an Array indeed (capitalized, formatted as code, builtin class name). So it's fine to refer to it as "an array" and the PoolStringArray return type specified in the signature tells you what kind of array exactly.

I see, inside godot i can see the return type :
godot-string-rsplit

But at godot website:
godot-help-page
Its not visible so its confuzing

Also i made the changes of the documentation as you can see but i have no idia how to make a pull request :/

Also! why is there a [code][/code] tag inside the xml, it adds no styling to the text from what i understand. It would be cool if it was styled with the same colors as in the editor

The built-in documentation lacks formatting (there's already an issue created for that #27456), but it's visible in the online version.

Fixed by #29467.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SleepProgger picture SleepProgger  路  3Comments

EdwardAngeles picture EdwardAngeles  路  3Comments

testman42 picture testman42  路  3Comments

gonzo191 picture gonzo191  路  3Comments

RayKoopa picture RayKoopa  路  3Comments