找回密码
 加入
搜索
查看: 1129|回复: 1

如何用正则为文本里面的行添加数据

[复制链接]
发表于 2010-1-25 10:37:20 | 显示全部楼层 |阅读模式
类似如下结构的数据:
10,Rigid ANC                                                               
          4(OPE),-1677,-1356,-6495,8251,-7712,970,-0.000,-0.000,-0.000
          5(OPE),-1693,-1334,-6491,8137,-7815,993,-0.000,-0.000,-0.000
          24(SUS),41,25,-3769,2735,154,-22,0.000,0.000,-0.000
          25(SUS),41,25,-3769,2735,154,-22,0.000,0.000,-0.000
70,Prog Design  VSH                                                               
          4(OPE),0,0,-1711,0,0,0,-31.880,-13.838,18.933
          5(OPE),0,0,-1713,0,0,0,-32.468,-13.020,18.811
          24(SUS),0,0,-2046,0,0,0,0.546,-2.790,0.603
          25(SUS),0,0,-2046,0,0,0,0.546,-2.790,0.603
要在4(OPE), 5(OPE),24(SUS), 25(SUS)前面添加前面的只有两列的行的数字,变为如下:
10,Rigid ANC                                                               
          10,4(OPE),-1677,-1356,-6495,8251,-7712,970,-0.000,-0.000,-0.000
          10,5(OPE),-1693,-1334,-6491,8137,-7815,993,-0.000,-0.000,-0.000
         10, 24(SUS),41,25,-3769,2735,154,-22,0.000,0.000,-0.000
          10,25(SUS),41,25,-3769,2735,154,-22,0.000,0.000,-0.000
70,Prog Design  VSH                                                               
          70,4(OPE),0,0,-1711,0,0,0,-31.880,-13.838,18.933
          70,5(OPE),0,0,-1713,0,0,0,-32.468,-13.020,18.811
          70,24(SUS),0,0,-2046,0,0,0,0.546,-2.790,0.603
         70, 25(SUS),0,0,-2046,0,0,0,0.546,-2.790,0.603

请问用正则如何实现呢?
发表于 2010-1-25 11:24:29 | 显示全部楼层
正则没弄。
$FHD=FileOpen("ttt.txt")
$txt=""
While 1
        $lin=FileReadLine($FHD)
        If @error Then ExitLoop
        $txt=$txt&$lin&@CRLF
        $TEST=StringRegExp($lin,",",3)
        If UBound($TEST)=1 Then
                For $i=1 To 4
                        $lins=FileReadLine($FHD)
                        $txt=$txt&"       "&StringLeft($lin,StringInStr($lin,","))&StringStripWS($lins,3)&@CRLF
                Next
        EndIf
WEnd
FileClose($FHD)
MsgBox(0,0,$txt)
        

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-16 19:47 , Processed in 0.120576 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表