使用AutoIt进行用户定义的排序比较 [英] User-defined sorting comparison using AutoIt
问题描述
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屋!