我的客户端需要将文本文件导入系统,但其文本文件是管道分隔符“|”。他们还需要将一些数据导出为相同的格式(管道分隔)。我被要求使用Powerbuilder 12.是否可以直接使用PipeDelimited Textfiles导入文件?我想跳过“FOR LOOP MID GET”方法并直接进入importfile然后更新()。 dw.saveas()同样如此。
答案 0 :(得分:0)
据我所知,我们对导入并不幸运,因为我们无法定义分隔符,但这里有一点解决方法:
我为你做了一个小测试应用程序,但它确实有效。我的文本文件是这样的:
Col1中| col2的| COL3
AAA | BBB | CCC
以下是导入代码:
string ls_import, ls_export
long ll_filehandle, ll_readbytes
// IMPORT
ll_filehandle = FileOpen("d:\Work\StackExchange\pipes.txt", TextMode!)
ll_readbytes = FileReadEx(ll_filehandle, ls_import)
if ll_filehandle = -1 or IsNull(ll_filehandle) then
else
ls_import = f_glo_replace_all(ls_import, "|", ",")
dw_1.ImportString(CSV!, ls_import)
end if
随着出口我们有更多的运气。有一种数据窗口方法,您可以在其中自定义导出的分隔符:
所以导入看起来像这样:
dw_1.SaveAsFormattedText(“d:\ Work \ StackExchange \ export_pipes.txt”,EncodingANSI!,“|”)
当然,您需要全局替换功能的代码:
以下是来源:
global type f_glo_replace_all from function_object
end type
forward prototypes
global function string f_glo_replace_all (string source, string look_for, string replace_with)
end prototypes
global function string f_glo_replace_all (string source, string look_for, string replace_with);/*A String Occurrence Search and Replace RoutineThe following code demonstrates a string occurrence search and replaceroutine.This routine works generically for any string. For example,if old_str = "red" and new_str ="green", all occurrences of "red" inside of mystring will be replaced with "green".
Parameters
Name = source Type = String
Name = look_for Type = String
Name = replace_with Type = String
*/
int start_pos=1,len_look_for
len_look_for = len(lower(look_for))
//find the first occurrence of look_for ...
start_pos = Pos(lower(source),lower(look_for), start_pos)
//only enter the loop if you find whats in look_for
DO WHILE start_pos > 0
//replace look_for with replace_with ...
source = Replace(source,start_pos,Len_look_for,replace_with)
//find the next occurrence of
start_pos = Pos(lower(source), lower(look_for), start_pos+Len(replace_with))
LOOP
return source
end function
我希望这有帮助!
溴。的Gabor
答案 1 :(得分:0)
不,你想要的方式是不可能的。您需要编写自己的ImportFile版本,抱歉这不是您想要的答案。