英文:
Progress Openedge : Defining Delimiter as variable?
问题
我一直在尝试弄清楚如何将分隔符用作变量。但是没有成功。有人有任何建议吗?
以下是我尝试过的,但它不起作用:
iLine = getLastHeaderLine().
cDelimiter = getDelimiter().
REPEAT:
IF iLine <= 1
THEN DO:
IMPORT UNFORMATTED csvRaLine.
END.
ELSE DO:
IMPORT UNFORMATTED csvLine.
IMPORT DELIMITER cDelimiter.
CREATE ttImportReport.
ttImportReport.Amount = ParseAmount(csvLine).
ttImportReport.Category = ParseCategory(csvLine).
ttImportReport.dDate = ParseDate(csvLine).
ttImportReport.cDescription = ParseDescription(csvLine).
ttImportReport.cState = ParseState(csvLine).
END.
iLine = iLine + 1.
END.
英文:
I have been trying to figure out how to use delimiter as a variable. However no go. Anyone got any suggestions?
This is what i have tried, however it does not work:
iLine = getLastHeaderLine().
cDelimiter = getDelimiter().
REPEAT:
IF iLine <= 1
THEN DO:
IMPORT UNFORMATTED csvRaLine.
END.
ELSE DO:
IMPORT UNFORMATTED csvLine.
IMPORT DELIMITER cDelimiter.
CREATE ttImportReport.
ttImportReport.Amount = ParseAmount(csvLine).
ttImportReport.Category = ParseCategory(csvLine).
ttImportReport.dDate = ParseDate(csvLine).
ttImportReport.cDescription = ParseDescription(csvLine).
ttImportReport.cState = ParseState(csvLine).
END.
iLine = iLine + 1.
END.
答案1
得分: 4
抱歉,分隔符必须是文字。
你能做的最好的办法是创建一个 IF ... THEN ... ELSE 或 CASE 语句来支持多个可能的分隔符。类似这样:
CASE myDelimiter:
WHEN ',' THEN
IMPORT DELIMITER ',' inputData.
WHEN '.' THEN
IMPORT DELIMITER '.' inputData.
WHEN '|' THEN
IMPORT DELIMITER '|' inputData.
END.
英文:
Unfortunately the delimiter must be a literal.
The best you can do is to create an IF ... THEN ... ELSE or CASE statement to support multiple possible delimiters. Something like this:
CASE myDelimiter:
WHEN ',' THEN
IMPORT DELIMITER ',' inputData.
WHEN '.' THEN
IMPORT DELIMITER '.' inputData.
WHEN '|' THEN
IMPORT DELIMITER '|' inputData.
END.
答案2
得分: 0
我认为你使用 IMPORT UNFORMATTED
的方法可以行得通,如果你真的需要一个可变的分隔符。因此,你的 Parse<field>()
方法可以接受第二个参数,即分隔符,以及输入行。
你会失去 IMPORT
语句处理嵌套分隔符的能力(例如,当你在引号中有逗号并且使用逗号作为分隔符时)。
英文:
I think your approach of using IMPORT UNFORMATTED
can work, if you really need a variable delimiter. So your Parse<field>()
methods could take a second parameter, the delimiter, along with the input line.
What you lose is the IMPORT
statement's ability to deal with nested delimiters (eg when you have a comma in quotes, and are using a comma as delimiter).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论