Progress OpenEdge:将分隔符定义为变量?

huangapple go评论50阅读模式
英文:

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).

huangapple
  • 本文由 发表于 2023年5月7日 03:52:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76190840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定