ABC+123:xy+123++23'EFG+123:xy+123++23'GHI+123:xy+223++23+mki+123'MV++123:xy'
我有上面的绳子。撇号(')充当表示段结束的终止符。因此,ABC+123:xy+123++23是一个段,它的起始标签是三个字符ABC,这是唯一的。现在我需要根据这些起始标签来修剪这个字符串,例如我需要只以ABC和LMV开头的片段。结果字符串应该是ABC+123:xy+123++23'LMV++123:xy'
根据这个问题和您的其他问题,您可以使用EDIFACT。
EDIFACT用单引号"(如果您愿意,也可以用撇号)分隔。
ENTRY
和NUM-ENTRIES
是你的朋友。我建议将数据移动到比字符串更可用的格式中,更确切地说是临时表。然后你可以用临时表做任何你想做的事。首先"逐行"或更确切地说"逐项"处理数据,然后继续使用它做任何你想做的事情
DEFINE VARIABLE cString AS CHARACTER NO-UNDO.
DEFINE VARIABLE iEntry AS INTEGER NO-UNDO.
DEFINE TEMP-TABLE ttEdifact NO-UNDO
FIELD lineno AS INTEGER
FIELD linedata AS CHARACTER FORMAT "x(60)".
/* The string in your example ends with a delimiter (') thus your temp-table will have one empty record in the end - it could be trimmed away */
cString = "ABC+123:xy+123++23'EFG+123:xy+123++23'GHI+123:xy+123++23+mki+123'LMV++123:xy'".
DO iEntry = 1 TO NUM-ENTRIES(cString, "'").
CREATE ttEdiFact.
ASSIGN
ttEdifact.lineno = iEntry
ttEdifact.lineData = ENTRY(iEntry, cString, "'").
END.
/* Now it's up to you to do something */
FOR EACH ttEdifact WHERE ttEdifact.lineData BEGINS "ABC":
DISP ttEdiFact.
END.