如何搜索带连字符的单词

How to search hyphenated words

如何搜索带连字符的词,例如(Alexander-great),如果这个词出现在搜索列表中,那么输出应该像 Alexander-great:1 here 1 表示特定词出现在主滚动字段 I 中的次数我正在使用以下代码。

on mouseUp
  put fld"MytextField"into Mytext   
put fld "SRText" into myData
   split myData by cr and colon
   put the keys of myData into myData

   repeat for each words myWord in Mytext
      if myWord is among the words of myData then
                  if myCounts[myWord] is empty then
            put 1 into myCounts[myWord]
            --answer "Haii"
         else
            add 1 to myCounts[myWord]

         end if
      end if
   end repeat
   combine myCounts by cr and colon
   put myCounts  

请使用此代码

if myWord contains the words of myData then 

而不是

if myWord is among the words of myData then

您的代码应该可以正常工作,但您可以检查一个稍微更紧凑的版本:

   ...
repeat for each words myWord in Mytext
       if myWord is among the words of myData then add 1 to myCounts[myWord]
end repeat
...  

LC 中的局部变量,包括数组变量,可以动态创建和加载。无需声明它们或使用默认值创建它们。请逐步执行处理程序,并观察变量 watcher 的内容。

请注意,您的方法并未被禁止,但不必要地冗长。当你变得更有经验时,你会变得更有效率。

克雷格·纽曼