[英]Finding a "whole string" within a string with Index (or another way)?
I am reading in a list of constituent attributes (tags) and only want to keep a subset of them.我正在阅读构成属性(标签)的列表,并且只想保留其中的一个子集。 Here is how I attempted to do that.
这是我尝试这样做的方式。
DEFINE VARIABLE tagsToKeep AS CHARACTER.
tagsToKeep = "Business Contact,Celebrate 2015,Celebrate 2017,Celebrate 2019,Certificate - Former Holder,Non-MB Church".
/*do a bunch of stuff to get the cRecord which is one tag, often with spaces or other characters in it.*/
IF INDEX(tagsToKeep, cRecord) > 0 THEN
DO:
CREATE ttTag.
ASSIGN
ttTag.tag-code = cRecord
ttTag.constituent-id = ttAccount.pin-string.
ttTag.tag-name = cRecord.
END.
The trouble is that one of the tags is "Certificate" which is a substring of one of the strings in the TagsToKeep string -- "Certificate - Former Holder" gets included and created as a Tag.问题在于其中一个标签是“Certificate”,它是 TagsToKeep 字符串中字符串之一的子字符串——“Certificate - Former Holder”被包含并创建为标签。 I only want to match on the strings that are essentially "whole word only".
我只想匹配本质上“仅整个单词”的字符串。
Is there a (better) way to do what I want to do?有没有(更好的)方法来做我想做的事?
If cRecord
is a single tag, then it may be useful to take the list of to-keep tags and put those tags into a separate temp-table如果
cRecord
是单个标签,那么获取要保留的标签列表并将这些标签放入单独的临时表中可能很有用
DEFINE VARIABLE loop AS INTEGER NO-UNDO.
DEFINE VARIABLE cnt AS INTEGER NO-UNDO.
// Define and populate temp-table
DEFINE TEMP-TABLE ttTagsToKeep NO-UNDO
FIELD TagName AS CHARACTER
INDEX idx1 AS PRIMARY UNIQUE TagName.
cnt = NUM-ENTRIES(cTagsToKeep).
DO loop = 1 to cnt:
CREATE ttTagsToKeep.
ASSIGN ttTagsToKeep.TagName = TRIM(ENTRY(loop, cTagsToKeep)).
END.
Now you can look for a matching record.现在您可以查找匹配的记录。 Whether you clean up
cRecord
or do multiple CAN-FINDs is up to you.是清理
cRecord
还是执行多个 CAN-FIND 取决于您。
IF CAN-FIND(ttTagsToKeep WHERE ttTagsToKeep.TagName EQ cRecord) THEN
DO:
// create ttTag record
END.
In your code, use LOOKUP instead of INDEX在您的代码中,使用 LOOKUP 而不是 INDEX
IF LOOKUP (cRecord, tagsToKeep) > 0 THEN
(comma-) delimited lists are a key concept in the ABL. (逗号-)分隔列表是 ABL 中的一个关键概念。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.