0

是否有任何 4GL 语句用于从磁盘编辑 ASCII 文件,如果有,如何?

4

5 回答 5

8

编辑包括读取文件,可能使用 IMPORT,然后使用 REPLACE() 等字符串函数操作文本,最后可能使用 PUT 写入结果。像这样的东西:

define stream inFile.
define stream outFile.

define variable txtLine as character no-undo.

input stream inFile from "input.txt".
output stream outFile to "output.txt".

repeat:

  import stream inFile unformatted txtLine.

  txtLine = replace( txtLine, "abc", "123" ).   /* edit something */

  put stream outFile unformatted txtLine skip.

end.

input stream inFile close.
output stream outFile close.
于 2009-08-28T20:31:47.033 回答
1

就在这里。您可以使用 STREAM 来执行此操作。

/* Define a new named stream */
DEF STREAM myStream.

/* Define the output location of the stream */
OUTPUT STREAM myStream TO VALUE("c:\text.txt").

/* Write some text into the file */
PUT STREAM myStream UNFORMATTED "Does this work?".

/* Close the stream now that we're done with it */
OUTPUT STREAM myStream CLOSE.
于 2009-08-24T18:01:26.730 回答
0

进度可以调用操作系统编辑器:

操作系统命令(“vi /tmp/yoyo.txt”)。

于 2009-09-04T17:24:53.473 回答
0

您可以使用 copy-lob 来读取和写入文件

DEF VAR lContents AS LONGCHAR NO-UNDO.

/* read file */
COPY-LOB FROM FILE "ascii.txt" TO lContents.
/* change Contents, e.g. all capital letters */
lContents = CAPS(lContents).
/* save file */
COPY-LOB lContents TO FILE "ascii.txt".
于 2013-08-21T06:03:02.327 回答
0

我认为对于“编辑”,您的意思是能够读取然后在屏幕上显示文件并操作文件?

如果是这样,那么在这里你有一个简单的,当然,文件的大小不能大于最大值。vchar 变量的容量:

def var fileline as char format "x(250)".  /* or shorter or longer, up to you*/
def var filedit as char.

/*you have to quote it to obtain & line into teh charvar*/

unix silent quoter kk.txt > kk.quoted.

input from kk.quoted no-echo.


repeat:

   set fileline.

   filedit = filedit + (fileline + chr(13) + chr(10)) .

end.

input close.

update filedit view-as editor size 65 by 10.

当然,您可以在编辑后设法保存文件;-)

于 2013-08-30T14:26:29.550 回答