使用 AutoIt 进行用户定义的排序比较 [英] User-defined sorting comparison using AutoIt
问题描述
PHP 具有 usort 而 Java 具有 比较器 接口.
PHP has usort and Java has the Comparator interface.
这些允许您创建一个简单的函数来比较两个对象、字符串等,而无需涉及排序实现的细节.
These allow you to create a simple function that compare two Objects, Strings, etc. without getting involved in the details of the sort implementation.
通常,比较函数看起来像这样:
// Return value:
// Negative value: a before b
// Positive value: b before a
// Zero: strings are equal
function compare(String a, String b) {
return toLowerCase(a) - toLowerCase(b);
}
...您可以根据自己的喜好进行简单或花哨的比较.
AutoIt 中有什么可以做到这一点的吗?
文档很棒,帮助文件也很棒,但是我找不到任何可以定义自定义比较函数的内容.(如有必要,我会重新实现 Quicksort,但使用像 AutoIt 这样功能齐全的框架,我觉得我一定只是忽略了一些东西.)
The documentation is great, and the Help File is great, but I cannot find anything that allows me to define a custom comparison function. (I will reimplement Quicksort if necessary, but with a framework as full-featured as AutoIt, I feel like I must just be overlooking something.)
推荐答案
"AutoIt 中有什么可以做到这一点的吗?"
示例如 _ArrayMultiColSort()
:
#include <Array.au3>
#include "ArrayMultiColSort.au3"
Global Const $g_sHeaderRow = 'category|value'
Global Const $g_aSortOrder = [ _
[0, 'critical,important,regular'], _
[1, 1] _
]
Global $g_aArray = [ _
['critical', 7], _
['important', 2], _
['important', 6], _
['regular', 2], _
['critical', 5], _
['regular', 9] _
]
_ArrayMultiColSort($g_aArray, $g_aSortOrder)
_ArrayDisplay($g_aArray, @ScriptName, '', 0, Default, $g_sHeaderRow)
返回:
critical 7
critical 5
important 6
important 2
regular 9
regular 2
这篇关于使用 AutoIt 进行用户定义的排序比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!