如何找到包含特定数字的行偏移量

How to find the line offset containing a specific number

我正在尝试使用以下代码

put 7 into lFoodID

lineoffset (lFoodID,gArrFood) into tArrFoodLine

在下面的数组中找到包含数字 7 的行

17  Banana
20  Beans
2   Beef
1   Bread
8   Cabagge
6   Chicken
5   Eggs
15  Ice Cream
3   Mango
7   Pork
18  Rice
4   Salad
19  fried fish

它返回 1。我知道这是因为 17 包含数字 7。我试过了

set the wholeMatches to true

但这也不管用。我相信正则表达式 (^(7) 应该可以工作,但我可以弄清楚如何在 lineoffset 中使用正则表达式。

我不确定你真正想要的是什么,我想知道你的数据是否真的像你在这里提供的那样。我假设您的数据与显示的一样,但这可能会导致解决方案与您真正想要的略有不同。

如果想获取与某个索引关联的产品,可以使用以下脚本

put fld 1 into myList
replace space&space with tab in myList
repeat until (tab&tab is not in myList and space&space is not in myList)
   replace space&space with space in myList
   replace tab&tab with tab in myList
end repeat
split myList by cr and tab
put myList[7] into myProduct
put myProduct

MyProduct 包含产品名称。请注意,如果您的数据格式正确,则不需要重复循环。如果你真的想要索引,使用这个:

put fld 1 into myList
put 7 into myIndex
if word 1 of myList is not myIndex then
   put number of lines of char 1 to offset(cr & "7" & space ,myList) of myList into myLine
else
   put 1 into myLine
end if
put myLine

MyLine 包含您列表中的完整记录。