如何用正则方法 将任意长度数字,间隔3位加个","?
比如 123456,变成123,456123不变,
1235900,变成1,235,900
12345678.90,变成12,345,678.90
刚学正则,以上的正则弄不来,高手请教! 有高手在线么,在线等ING 这个以前弄过,得找找。记得可以不用正则 :face (31):A大 加油 回复 4# superflq
找到了,我再测试整理下,等下发到UDF区~ 是用正则的么 非正则 那么复杂,需要变成UDF啊 $a1=InputBox(0,"","")
Dim $text
If StringIsDigit ($a1)=1Then
For $i =3 To StringLen ($a1) Step 3
If $i-StringLen ($a1)=0 Then
$text=StringLeft($a1,3)&$text
ExitLoop
EndIf
$text=$text&","&StringMid ($a1,StringLen ($a1)-$i,3)
Next
MsgBox(0,"",StringLeft ($a1,Mod ( StringLen ($a1) , 3 ))&$text)
EndIf $a1=InputBox(0,"","")
Dim $text
If StringIsDigit ($a1)=1Then
For $i =3 To StringLen ($a1) Step ...
jhun 发表于 2010-4-9 16:05 http://www.autoitx.com/images/common/back.gif
有些问题,你再测试下,比如输入1234,得到1,123 是用正则的么
superflq 发表于 2010-4-9 14:39 http://www.autoitx.com/images/common/back.gif
正在按你的要求改用正则…… 有些问题,你再测试下,比如输入1234,得到1,123
afan 发表于 2010-4-9 16:09 http://www.autoitx.com/images/common/back.gif
不好意思,自己测试全是输1的,所以……我再检查下 $a1=InputBox(0,"","")
Dim $text
If StringIsDigit ($a1)=1Then
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,",,",","))
EndIf
应该能用了,写得很恶心,不想改了,身体不舒服 $a1=InputBox(0,"","")
Dim $text
If StringIsDigit ($a1)=1Then
For $i =3 To StringLen ($a1) Step ...
jhun 发表于 2010-4-9 16:37 http://www.autoitx.com/images/common/back.gif
辛苦了,可是要是123456.12就直接出错
只要带"."+数字就会出错 不是出错,是我一开始就没打算有小数点,所以加了句If StringIsDigit ($a1)=1Then
有小数点直接不执行,不过就算去掉这句也不行,要重写,我再加上吧
页:
[1]
2