我今天刚刚写了一段程序,实现对一个text cast member中的文本进行关键字搜索。没有使用xtra。
我采用的是逐行搜索,我的文本很大,存成txt文件,有600k。
平均的搜索时间在5秒以上,很慢,有没有更快的方法?
原程序如下:
property pSearchTextName
property pPathNum,pNameNum
on beginSprite me
--要搜索文本的名字
pSearchTextName = "Content"
pPathNum = 1
pNameNum = 1
end
on mouseUp me
--searchWhat:用户输入的关键字
searchWhat = member("input").text
--跳转到搜索程序模块
GoSearchNow(searchWhat)
end
--搜索程序模块
on GoSearchNow WhatSearch
--开始计时
startTimer
--NumOfLine:目标搜索文本的行数
NumOfLine = member(pSearchTextName).line.count
--开始循环搜索
repeat with i = 1 to NumOfLine
TextOfCurrentLine = member(pSearchTextName).line[i]
temp = offset(WhatSearch,TextOfCurrentLine)
if temp > 0 then
GetPath(i)
end if
end repeat
TotalTime = the timer/60
member("searchTime").line[2] = string(TotalTime) & " 秒"
end
on GetPath currentLine
repeat with j = currentLine down to 1
if member(pSearchTextName).line[j].char[1..3] = "z:\" then
temp1 = member(pSearchTextName).line[j].char.count
member("outputPath").line[pPathNum] = member(pSearchTextName).line[j].char[3..temp1]
pPathNum = pPathNum + 1
temp2 = member(pSearchTextName).line[j+1].char.count
member("outputName").line[pNameNum] = member(pSearchTextName).line[j+1]
pNameNum = pNameNum + 1
exit repeat
end if
end repeat
end