diff options
author | Lisandro Lorea <lisandrolorea@gmail.com> | 2022-01-15 20:07:01 -0300 |
---|---|---|
committer | Lisandro Lorea <lisandrolorea@gmail.com> | 2022-01-17 15:11:50 -0300 |
commit | 176a9c738fed0ed139d6971c089157bfc80b30f9 (patch) | |
tree | e07e19e0a4b0d16aedeecc86b39f79c2b64e8ae5 /doc/classes | |
parent | 324dca57af03df66b6314cc29f46f8ebb4ec59b2 (diff) |
Give example of one-liner for Array natural sort
The documentation for the sort method warns the user that it doesn't do natural sort but fails to provide a solution when it's just a one liner thanks to String.naturalnocasecmp_to() and lambda support
This suggests exactly the same algorithm as used by the filesystem dock for file sorting.
Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
Diffstat (limited to 'doc/classes')
-rw-r--r-- | doc/classes/Array.xml | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 5b1861bc9a..7cb6f71190 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -470,6 +470,12 @@ // There is no sort support for Godot.Collections.Array [/csharp] [/codeblocks] + To perform natural order sorting, you can use [method sort_custom] with [method String.naturalnocasecmp_to] as follows: + [codeblock] + var strings = ["string1", "string2", "string10", "string11"] + strings.sort_custom(func(a, b): return a.naturalnocasecmp_to(b) < 0) + print(strings) # Prints [string1, string2, string10, string11] + [/codeblock] </description> </method> <method name="sort_custom"> |