我有两个滚动字段,一个包含一些文本,另一个包含一些单词。例如。 (s1:s2)用冒号分隔我的目标是找到第二个滚动中有多少单词出现在第一个滚动字段中。 (例如:如果s1出现在第一个滚动字段中,则表示s1,1表示s1出现一次)。在执行我的代码时它是有效的,但是如果我的第一个滚动字段为空,它会显示一些文本,有时也会在第一个字段中显示一些单词。 (例如:\ documentclass)这个词不在2'nd字段中。
我正在使用以下代码。
global ar
global sam
on mouseUp
--set the caseSensitive to true
put 0 into tmp
put empty into sam
put the field SRText into myArrayT
split myArrayT by CR
put the number of lines of (the keys of myArrayT) into myArrayl
repeat for each key j in myArrayT
put myArrayT[j] into k
split k by colon
put k[1] into searchStr1
put the field "MytextField" into sss
repeat for each word ass in sss
if ass contains searchStr1 then
add 1 to tmp
put ass & CR & CR after sam
put sam into ar
end if
end repeat
end repeat
answer sam
answer tmp
--answer sa
end mouseUP
on mouseDown
answer ar
put ar into ss
get ss
repeat for each word tWord in it
add 1 to wordCount[tword]
end repeat
combine wordCount by return and comma
answer wordCount
--put empty into sam
end mouseDown
答案 0 :(得分:0)
你真的应该在字段名称周围使用引号。我保证有一天你会意识到,你一直在为自己的脚射击。
不要在对象引用前使用the
,
field "Field Name"
button "Field name"
但请在属性引用前使用the
:
the number of lines of fld "Field Name"
the text of fld "Field Name"
the name of this stack
你真的没有理由对数组进行痴迷。不需要时停止使用数组!它只是让事情过于复杂和缓慢。
我修改了你的mouseUp处理程序。我没有看你的mouseDown处理程序。我相信你的mouseUp处理程序应如下所示:
on mouseUp
--set the caseSensitive to true
put 0 into tmp
put empty into sam
repeat for each line k in fld "SRText"
set the itemDel to colon
put item 1 of k into searchStr1
repeat for each word ass in field "MytextField"
if ass contains searchStr1 then
add 1 to tmp
put ass & colon & tmp & cr after sam
end if
end repeat
put 0 into tmp
end repeat
put sam
end mouseUp
上面的脚本是基于你的方法,我真的不明白为什么你会这样做,以及你将如何处理结果。下面的脚本可能效率更高,对我来说似乎更有用。
on mouseUp
// I assume fld SRText contains a list similar to
// "abc:1" & cr & "bcd:2" & cr & "cde:1" & cr & "def:4"
put fld "SRText" into myData
split myData by cr and colon
put the keys of myData into myData
// myData is not an array!
repeat for each word myWord in fld "MytextField"
if myWord is among the lines of myData then
// use an array to store data, not to loop through
if myCounts[myWord] is empty then
put 1 into myCounts[myWord]
else
add 1 to myCounts[myWord]
end if
end if
end repeat
combine myCounts by cr and colon
put myCounts
end mouseUp