作者在 2015-02-26 20:28:59 发布以下内容
下面一段数据,要求遇到字母时开始换行。如何做到?
B0F0090504210807000220202020024033080000080000180A09021309032909021909021900011000000000ED21080700000000000800000000651056000000000380032000000244000000000000000000000898B4032108070000000000080000010890A887210807090224090224
换行后变成下面
B0F0090504210807000220202020024033080000080000180
A09021309032909021909021900011000000000
ED21080700000000000800000000651056000000000380032000000244000000000000000000000898
B4032108070000000000080000010890
A887210807090224090224
lcstr="B0F0090504210807000220202020024033080000080000180A09021309032909021909021900011000000000ED21080700000000000800000000651056000000000380032000000244000000000000000000000898B4032108070000000000080000010890A887210807090224090224"
lcstr1=""
lle=.t.
for lnI=1 to len(lcstr)
cstr=substr(lcstr,lnI,1)
if isalpha(cstr) and lle=.t.
lle=.f.
lcstr1=lcstr1+CHR(10)+chr(13)+cstr
else
lle=.t.
lcstr1=lcstr1+cstr
endif
endfor
strtofile(lcstr1,"gg1.txt")
modify file gg1.txt
改进方法
为了使代码更具可读性,对上面的代码做了如下改进(2015-03-29)
clear
lcText ="B0F0090504210807000220202020024033080000080000180A09021309032909021909021900011000000000ED21080700000000000800000000651056000000000380032000000244000000000000000000000898B4032108070000000000080000010890A887210807090224090224"
Bla=.F.
lcStr=""
For lnI=1 To Len(lcText)
lcC=Substr(lcText,lnI,1)
Blb =Isalpha(lcC) && 判断是否为字母
If Blb!=Bla And Blb=.T.
lcStr=lcStr+Chr(13)+Chr(10)
EndIf
lcStr=lcStr+lcC
Bla=Blb
EndFor
MessageBox(lcStr,0,"显示结果")