找回密码
 加入
搜索
楼主: superflq

[效率算法] 如何用正则方法 将任意长度数字,间隔3位加个","?

  [复制链接]
发表于 2010-4-9 17:01:57 | 显示全部楼层
显然写成这样,用正则好得多,不过正则有人写了,我就用不用正则的来写吧,呵呵

$a1=InputBox(0,"","")
Dim $text
If StringIsDigit (StringReplace ($a1,".",""))=1 Then
        For $i=1 To StringLen ($a1)
                If StringMid ($a1,$i,1)= "." Then $k=StringMid ($a1,$i,StringLen ($a1)-$i+1)
        Next
        $a1=StringReplace ($a1,$k,"")
        If StringIsDigit ($a1)=1  Then
                For $i =3 To StringLen ($a1) Step 3
                        If $i-StringLen ($a1)=0 Then
                                $text=StringLeft($a1,3)&$text
                                ExitLoop
                        EndIf
                        $text=","&StringMid ($a1,StringLen ($a1)-$i+1,3)&","&$text
                Next
                If StringRight ( $text, 1 )="," Then $text=StringTrimRight ( $text, 1 )
                MsgBox(0,"",StringReplace (StringLeft ($a1,Mod ( StringLen ($a1) , 3 ))&$text,",,",",")&$k)
        EndIf
EndIf
发表于 2010-4-9 17:16:43 | 显示全部楼层
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-15 12:38 , Processed in 0.110193 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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