我在从文本文件解析 CSV 时遇到问题,想知道你们是否可以帮助我。到目前为止,我有以下内容,
CSV 文件 (DATA.txt) 看起来像这样,它总是有 15 个字段,全部用逗号分隔。并非所有字段都是强制性的,因此有些字段将被填写,有些字段为空白。
Seattle,Lastname,Firstname,DOB,SEX,etc,etc
Seattle,Lastname,Firstname,DOB,,etc,etc
Portland,Lastname,Firstname,DOB,SEX,,,etc
Portland,Lastname,Firstname,DOB,SEX,etc,etc
这是我的 REXX 代码
SOURCEFILE = "C:\DATA\DATA.TXT"
IF A=2 THEN DO COUNTER=1 TO LINES(SOURCEFILE)
PARSE VALUE LINEIN(SOURCEFILE) WITH CITY "," LAST_NAME "," FIRST_NAME "," MOM_NAME "," MIDDLE_NAME "," DAD_NAME "," DOB "," etc "," etc "," etc "," etc "," SEX "," etc "," etc
CALL SETCURSOR 4,23
CALL CREATEDATA
END
CREATEDATA:
CALL TYPE CITY
CALL PRESS TAB
CALL TYPE LAST_NAME
CALL PRESS TAB
CALL TYPE DATE(U)
CALL PRESS TAB
CALL TYPE FIRST_NAME
CALL PRESS TAB
CALL PRESS ENTER
RETURN
我不确定在解析时是否应该使用 ARG 或 VAR,或者我是否正确编写了前两行。事实上,我知道我的 CREATEDATA 函数可以正常工作,因为我输入的是“CITY”,但不是解析的值。任何帮助将不胜感激。谢谢!