字符串替换巨慢
要把某一文本导到数据窗口,但是其间分割不用TAB,所以先换做TAB,在DW_1.IMPORTFILE(STRING)
A001307|5324232790375015|54.26|海宁市三杰化工有限公司|17612|0|34|1.20|3.26|40.80|34|10.20|联合路127号|
如上字符串,当此字符串很多时,有1M之多,速度会很慢,(128m+cii950+win98),用了4个小时!!!
DEBUG,发现在用TAB 替换'|'时,花费了超多的时间,
请问有没好的解决方法,替换代码如下:
/函数功能:将非TAB分割符文本文件倒入数据窗口
//参数:adw_name :数据窗口
// as_filename :倒入文件名
// ac_separator:分割符,如“|”
//kukoc http://kjx.126.com
long ll_start_pos = 1
string ls_mystring
string ls_tempfile //临时文件
integer li_FileNum
integer li_loops
integer li_rtn
integer li_i
char lc_tab
long ll_flen
blob lb_b
blob lb_tot_b
ll_flen = FileLength(as_filename)
if ll_flen <= 0 then return -1
li_FileNum = FileOpen(as_filename,StreamMode!, Read!)
If isnull(li_FileNum) or li_FileNum < 0 then return -2
// 统计循环次数
IF ll_flen > 32765 THEN
IF Mod(ll_flen, 32765) = 0 THEN
li_loops = ll_flen/32765
ELSE
li_loops = (ll_flen/32765) + 1
END IF
ELSE
li_loops = 1
END IF
// 读文件
FOR li_i = 1 to li_loops
FileRead(li_FileNum, lb_b)
lb_tot_b = lb_tot_b + lb_b
NEXT
//关闭文件
FileClose(li_FileNum)
//转为字符串
ls_mystring = String ( lb_tot_b )
lc_tab = char(9) //TAB分割符
//找第一个分割符
ll_start_pos = Pos(ls_mystring, ac_separator, ll_start_pos)
If ll_start_pos <= 0 then
Messagebox('提示信息','文件内没有“' + ac_separator+ '”分割符 ')
return -10
End if
//循环替换分割符 此循环花时最多.
DO WHILE ll_start_pos > 0
//替换分割符
ls_mystring = Replace(ls_mystring, ll_start_pos, 1, lc_tab)
//找下一个分割符
ll_start_pos = Pos(ls_mystring, ac_separator, ll_start_pos + 1)
LOOP
lb_tot_b = blob(ls_mystring)
ll_flen = len(lb_tot_b)
// 统计循环次数
IF ll_flen > 32765 THEN
IF Mod(ll_flen, 32765) = 0 THEN
li_loops = ll_flen/32765
ELSE
li_loops = (ll_flen/32765) + 1
END IF
ELSE
li_loops = 1
END IF
//在当前目录下生成临时文件
ls_tempfile = GetCurrentDirectory() + "\importfile_tmp.txt"
If FileExists ( ls_tempfile ) Then
Messagebox('提示信息','临时文件' + ls_tempfile + '已经存在!')
return -1
End if
//打开临时文件
li_FileNum = FileOpen(ls_tempfile, &
StreamMode!, Write!, LockWrite!, Append! )
// 写到临时文件中
FOR li_i = 0 to li_loops - 1
lb_b = BlobMid(lb_tot_b, li_i * 32765 + 1, 32765)
FileWrite(li_FileNum, string(lb_b) )
NEXT
//关闭临时文件
FileClose(li_FileNum)
//将临时文件内容倒入数据窗口
li_rtn = adw_name.ImportFile(ls_tempfile)
//删除临时文件
FileDelete ( ls_tempfile )
return li_rtn