2

再会。下面是一个 Powerbuilder 脚本,用于检查文件编码并从文件中获取数据。一旦数据被分配给一个字符串变量(ls_encoding),它将被传递给对象函数,of_TabDelimited()(这个函数的脚本也显示在下面)以将分隔的管道替换为制表符分隔。

在对象函数内部of_TabDelimited(),应用程序挂起,我无法弄清楚 PB 挂起的原因。传递的数据约为 2,800 行。但是,of_TabDelimited()如果数据不是更大的行(例如 100 行),则该功能可以正常工作。我找不到处理的任何限制,of_TabDelimited()因为它只在循环内执行循环和替换功能。

任何人都可以帮助我如何查找和纠正错误?感谢任何帮助。

//Get the data from the file
ll_FileNum = FileOpen(ls_sourcepath, StreamMode!, Read!, LockWrite!, Replace!)
ll_FileLength = FileLength(ls_sourcepath)
eRet = FileEncoding(ls_sourcepath)
IF NOT ISNULL(ll_FileLength) OR ll_FileLength > 0 THEN  
    IF eRet = EncodingANSI! THEN 
        ll_bytes = FileReadEx(ll_FileNum, lbl_data)     
        ls_Encoding = String(lbl_data, EncodingUTF8!)   
        FileClose(ll_FileNum)
    END IF
ELSEIF ISNULL(ll_FileLength) OR ll_FileLength = 0 THEN 
    lb_Return = FALSE
END IF

Integer li_start, li_end
//Convert the data to TabDelimited
ls_Return = of_TabDelimited(ls_Encoding) //Application hang-up on this function.
IF NOT ISNULL(ls_Return) OR LEN(ls_Return) > 0 THEN 
    //Parse To Table
END IF


Function        : of_TabDelimited
Return Type     : String
Argument Type   : as_encoding

Long ll_start=1
String ls_old, ls_new
ls_old = "|"
ls_new = "~t"

// Find the first occurrence of old_str.
ll_start = POS(as_encoding, ls_old, ll_start)

// Only enter the loop if you find old_str.
DO WHILE ll_Start > 0
     // Replace old_str with new_str.
     as_encoding = Replace(as_encoding, ll_start, Len(ls_old), ls_new)

    // Find the next occurrence of old_str.
    ll_start = POS(as_encoding, ls_old, ll_start + Len(ls_new))
LOOP    

RETURN as_encoding

下面是我在应用程序中添加并测试的一个新功能。看来这个脚本运行良好,可以处理大量行。基本上,这个脚本取自 PFC 的函数 of_GlobalReplace(),取自对象 n_cst_string。甚至 of_TabDelimited() 中的脚本也取自 of_GlobalReplace(),但不同之处在于变量 ls_old 和 ls_new 中 len() 的计算。

String ls_Source, ls_Old, ls_New
Long ll_Start, ll_Oldlen, ll_Newlen
ls_Old = "|"
ls_New = "~t"

//Script taken from n_cst_string - of_GlobalReplace
//Get the string lenghts
ll_OldLen = Len(ls_Old)
ll_NewLen = Len(ls_New)

//Search for the first occurrence of as_Old
ll_Start = Pos(as_source, ls_Old)

Do While ll_Start > 0
    // replace as_Old with as_New
    as_Source = Replace(as_Source, ll_Start, ll_OldLen, ls_New)

    // find the next occurrence of as_Old
    ll_Start = Pos(as_source, ls_Old, (ll_Start + ll_NewLen))
Loop

Return as_Source
4

1 回答 1

0

我去查看了 PFC 的 of_GlobalReplace() 函数并从那里复制了脚本,但我删除了区分大小写的检查。我去测试了下面的函数,它在处理文件中的大量数据时工作正常。

String ls_Source, ls_Old, ls_New
Long ll_Start, ll_Oldlen, ll_Newlen
ls_Old = "|"
ls_New = "~t"

//Script taken from n_cst_string - of_GlobalReplace
//Get the string lenghts
ll_OldLen = Len(ls_Old)
ll_NewLen = Len(ls_New)

//Search for the first occurrence of as_Old
ll_Start = Pos(as_source, ls_Old)

Do While ll_Start > 0
    // replace as_Old with as_New
    as_Source = Replace(as_Source, ll_Start, ll_OldLen, ls_New)

    // find the next occurrence of as_Old
    ll_Start = Pos(as_source, ls_Old, (ll_Start + ll_NewLen))
Loop

Return as_Source
于 2015-11-04T08:01:31.327 回答