如何在制表符分隔的数组中进行全词搜索
How to do a whole word search in a tab separated array
我有一个类似于下面列表的数组。
我需要通过查找它出现在哪一行来找到颜色的 ID,该行的第一项是颜色的 ID。
我尝试了以下代码,但它不起作用,因为我相信它是在整行中搜索整个单词。如何更改代码以使行偏移仅适用于每行的第二项?
set the wholeMatches to true
put lineOffset("red",colors) into theLine
1 蓝色
2粉色
3 橙红色
4橙色
5 绿色
6 红色
7 黑色
8黄色
LineOffset 搜索多行,但在您的示例中,您只有一行。通常,您可以在一行中使用 wordOffset,但您面临着一个额外的挑战,因为您的一个颜色名称使用了多个单词。因此,您可以将所有单词视为项目并改用 itemOffset 函数:
put "1 blue 2 pink 3 reddish orange 4 orange 5 green 6 red 7 black 8 yellow" into theList
set the itemDel to space
set the wholeMatches to true
put itemOffset("reddish orange",theList) - 1 into N
put item N of theList into theColorID
编辑了附加信息:
获得线路真的很重要吗)?你可以试试:
put returnNum("Diarrhea",gArrSymptoms)
function returnNum tItem, list
repeat for each line L in list
put L into tempL
delete word 1 of tempL
set the wholeMatches to true
if lineOffset(tItem, tempL) >0 then return word 1 of L
end repeat
end returnNum
另外,colors是LiveCode中的保留字,所以这里使用了tColors
假设您有一个包含以下数据的字段:
2 Abdominal cramps
11 Abdominal pain
7 Bloody Diarrhea
16 Confusion
8 Cramps
5 Diarrhea
9 Facial pallor
6 Fever
13 Headache
12 Jaundice
3 Nausea
14 Stiff neck
10 Tea-colored urine
4 Vomiting
1 Watery diarrhea
15 Weakness
每条记录中包含行分隔记录和制表符分隔项。您可以使用以下语法检索列表中任何症状的 ID 号:
put word 1 of line (lineoffset(tab & "Headache"& cr,fld 1 & cr)) of fld 1
您也可以使用过滤器命令。
filter lines of gArrSymptoms with "*" & tab & theSymptom & "*" into temp
put word 1 of temp into theIndex
其中 "theSympton" 是您要查找的症状,"theIndex" 是您想要的数字。
* 是用于捕捉行首和行尾的通配符。
需要 "tab" 以确保次要组件不会先于主要组件被选取。
例如"Diarrhea" 作为次要术语被包含两次,一次作为主要术语被包含。
这让我想知道您如何确保首先选择正确的术语。
如果您的数组位于列表字段中,那么该字段的以下脚本也会为您提供所需的索引..
on mouseup
put word 1 of the hilitedline of me
end mouseup
我有一个类似于下面列表的数组。
我需要通过查找它出现在哪一行来找到颜色的 ID,该行的第一项是颜色的 ID。
我尝试了以下代码,但它不起作用,因为我相信它是在整行中搜索整个单词。如何更改代码以使行偏移仅适用于每行的第二项?
set the wholeMatches to true
put lineOffset("red",colors) into theLine
1 蓝色
2粉色
3 橙红色
4橙色
5 绿色
6 红色
7 黑色
8黄色
LineOffset 搜索多行,但在您的示例中,您只有一行。通常,您可以在一行中使用 wordOffset,但您面临着一个额外的挑战,因为您的一个颜色名称使用了多个单词。因此,您可以将所有单词视为项目并改用 itemOffset 函数:
put "1 blue 2 pink 3 reddish orange 4 orange 5 green 6 red 7 black 8 yellow" into theList
set the itemDel to space
set the wholeMatches to true
put itemOffset("reddish orange",theList) - 1 into N
put item N of theList into theColorID
编辑了附加信息:
获得线路真的很重要吗)?你可以试试:
put returnNum("Diarrhea",gArrSymptoms)
function returnNum tItem, list
repeat for each line L in list
put L into tempL
delete word 1 of tempL
set the wholeMatches to true
if lineOffset(tItem, tempL) >0 then return word 1 of L
end repeat
end returnNum
另外,colors是LiveCode中的保留字,所以这里使用了tColors
假设您有一个包含以下数据的字段:
2 Abdominal cramps
11 Abdominal pain
7 Bloody Diarrhea
16 Confusion
8 Cramps
5 Diarrhea
9 Facial pallor
6 Fever
13 Headache
12 Jaundice
3 Nausea
14 Stiff neck
10 Tea-colored urine
4 Vomiting
1 Watery diarrhea
15 Weakness
每条记录中包含行分隔记录和制表符分隔项。您可以使用以下语法检索列表中任何症状的 ID 号:
put word 1 of line (lineoffset(tab & "Headache"& cr,fld 1 & cr)) of fld 1
您也可以使用过滤器命令。
filter lines of gArrSymptoms with "*" & tab & theSymptom & "*" into temp
put word 1 of temp into theIndex
其中 "theSympton" 是您要查找的症状,"theIndex" 是您想要的数字。
* 是用于捕捉行首和行尾的通配符。
需要 "tab" 以确保次要组件不会先于主要组件被选取。 例如"Diarrhea" 作为次要术语被包含两次,一次作为主要术语被包含。
这让我想知道您如何确保首先选择正确的术语。
如果您的数组位于列表字段中,那么该字段的以下脚本也会为您提供所需的索引..
on mouseup
put word 1 of the hilitedline of me
end mouseup