cxm23 发表于 2010-12-19 02:26:30

[已解决]数组中有中文就不能搜索?

本帖最后由 cxm23 于 2010-12-19 10:11 编辑

#include <array.au3>

Local $avArray
$avArray = "张三"
$avArray = "李四"
$avArray = "王五"
$avArray = "JdeB"
$avArray = "Tylo"

Local $avArray1
$avArray1 = "aa"
$avArray1 = "bb"
$avArray1 = "cc"
$avArray1 = "JdeB"
$avArray1 = "Tylo"

MsgBox(1,1,_ArrayBinarySearch($avArray1,"JdeB"))

MsgBox(1,1,_ArrayBinarySearch($avArray,"李四"))

MsgBox(1,1,_ArrayBinarySearch($avArray,"JdeB"))结果:
3
-1
-1

dwilly 发表于 2010-12-19 08:45:33

我是来参观的

水木子 发表于 2010-12-19 09:22:14

我试了,确实是这样的,如果将数组中的内容转换成二进制再搜索不知道是什么结果。

蜘蛛抱蛋 发表于 2010-12-19 10:05:24

ArrayBinarySearch使用前必须排序,否则改用ArraySearch#include <array.au3>

Local $avArray = ["hello","李四","王五","JdeB","Tylo"]

Local $avArray1
$avArray1 = "aa"
$avArray1 = "bb"
$avArray1 = "cc"
$avArray1 = "JdeB"
$avArray1 = "Tylo"

MsgBox(1,1,_ArrayBinarySearch($avArray1,"JdeB"))
$t = _ArraySearch($avArray,"王五")
If @error Then
    MsgBox(1,1,@error)
Else
        MsgBox(1,1,$t)
EndIf

_ArraySort($avArray)
_ArrayDisplay($avArray, "排序后")
MsgBox(1,1,_ArrayBinarySearch($avArray,"王五"))

cxm23 发表于 2010-12-19 10:07:32

{:face (245):} 连数字串也不行#include <array.au3>

Local $avArray
$avArray = "张三"
$avArray = "李四"
$avArray = "王五"
$avArray = "JdeB"
$avArray = "Tylo"

Local $avArray1
$avArray1 = "aa"
$avArray1 = "bb"
$avArray1 = "cc"
$avArray1 = "1101"
$avArray1 = "Tylo"

MsgBox(1,1,_ArrayBinarySearch($avArray1,"Tylo"))

MsgBox(1,1,_ArrayBinarySearch($avArray1,"1101"))

MsgBox(1,1,_ArrayBinarySearch($avArray,"李四"))

MsgBox(1,1,_ArrayBinarySearch($avArray,"JdeB"))

cxm23 发表于 2010-12-19 10:10:15

{:face (239):}
原来如此,帮助里有:
注意
当执行二进制搜索时,内容必须先排序. 否则将返回未定义结果.

没注意看。。。汗

ahphsautoit 发表于 2010-12-19 19:28:00

我是来参观的
dwilly 发表于 2010-12-19 08:45 http://www.autoitx.com/images/common/back.gif

又遇到你了,你就是那个版主说金钱和贡献都成负数的传奇人物......
页: [1]
查看完整版本: [已解决]数组中有中文就不能搜索?