字符串替换问题二

文本(文件)数据问题 | 2015-02-26 20:28:59 | 阅读 878 次 | 评论(0)

下面一段数据,要求遇到字母时开始换行。如何做到?

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,"显示结果")






文章评论,共0条
游客请输入验证码
浏览234482次
最新评论
  • cstdio:ooooooo
  • sdta:从VFP入手也不错
  • yuanhouwen:尊敬的sdta大神:作为一个编程外行,看到你关于操控EXCEL的编程程序我觉得特别神奇,想向你...