如何在导出文本文件时删除空行?

How to remove an empty lines while exporting the text files?

DEFINE VARIABLE cExportData AS CHARACTER NO-UNDO FORMAT 'X(250)'.
DEFINE VARIABLE cPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE cExt  AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSFTL AS CHARACTER NO-UNDO FORMAT 'X(150)'.
DEFINE VARIABLE cMessageDateTime AS CHARACTER NO-UNDO.

ASSIGN
      cPath  = "R:\Downloads\progress\".
      cExt   = ".Txt".
      cMessageDateTime = "123456789".



OUTPUT TO VALUE (cPath + cMessageDateTime + STRING(MTIME) + cExt ).   


     cExportData = "Data1" + CHR(10) + "Data2" + CHR(10) + "Data3" + CHR(10) + "END.".
     MESSAGE  cExportData.

OUTPUT TO CLOSE.

所以当我看到使用记事本++导出的文本文件时,我可以看到 Data1、Data2、Data3 的前 3 个,但是第 4 行是用 empty.How 创建的,我是否停止创建空行。

MESSAGE 通常不是您想要用于输出到文件的内容,它有许多特定于在提供错误消息等上下文中与用户交互的额外行为。PUT 通常更适合写入文件。嵌入 CHR(10) 也不是一个好主意——这是一个非常 OS 特定的行终止符。 CHR(10) 是一个 Unix 风格的换行符,但你在 Windows 上显然是 运行(它使用 CHR(10) + CHR(13).

我可能re-write你的代码如下:

DEFINE VARIABLE cExportData AS CHARACTER NO-UNDO FORMAT 'X(250)'.
DEFINE VARIABLE cPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE cExt  AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSFTL AS CHARACTER NO-UNDO FORMAT 'X(150)'.
DEFINE VARIABLE cMessageDateTime AS CHARACTER NO-UNDO.

/* the "." that you had at the ends of the ASSIGN sub statements
 * is turning it into 3 distinct statements, not one as your 
 * indentation shows
 */

ASSIGN
  cPath  = "R:\Downloads\progress\" 
  cExt   = ".Txt"
  cMessageDateTime = "123456789"
. /* end the ASSIGN statement */

/* if you are using MTIME because you imagine it will make your
 * filename unique then you are mistaken, on a multi-user or 
 * networked system it is trivial for 2 processes to create files
 * at the very same MTIME
 */

OUTPUT TO VALUE (cPath + cMessageDateTime + STRING(MTIME) + cExt ).   

/* usually some kind of looping structure would output each line
 * building the whole output by concatenating into a string will
 * eventually exhaust memory.
 */ 

put unformatted "Data1" skip "Data2" skip "Data3" skip "End." skip.

/* the final SKIP might not be needed - it is unclear to me
 * if that is a problem for your client
 */

/* as originally written this creates
 * an empty file called "CLOSE"
 */

OUTPUT /*** TO ***/ CLOSE.