将小数位添加到字符串中的所有数字的最佳vbscript代码是什么?

What is the best vbscript code to add decimal places to all numbers in a string?

(P)例如(p)(P)G76 I0.4779 J270 K7 C90(p)(P)X20 Y30(p)(P)If a number begins with I J K C X and i t doesn't have a Decima They add Decima.Above example should look like:(p)(P)G76 I0.4779 J270 k7C90.(p)(P)X20。Y30.(p)(P)Purpose of this code is to turn CNC code for an older fanuc OPC controller(p)


1
2
3
4
<wyn>Set RegEx = New RegExp
RegEx.Global = True
RegEx.Pattern ="([IJKCXY]\d+)([^\.]|$)"
newVar = RegEx.Replace (oldString,"$1.$2")

代码>

其中oldstring是原始字符串,newvar是添加小数的字符串。


t仍然回答不起作用

韦恩斯工作,但也放了一个。每次发生ijkxy后

如果instr(match.value,".")=0,则更改。

如果instr(match.value,".")=0且len(match.value)大于1,则


1
2
3
4
5
6
7
8
9
10
11
12
13
function convert(str)
    Set RegEx = New RegExp
    RegEx.Global = True
    RegEx.Pattern ="([IJKCXY]\d*\.?\d*)"
    Set Matches = regEx.Execute(str)

    For Each Match in Matches
        if instr(Match.value,".") = 0 then
            str = Replace(str, Match.value, Match.value &".")
        end if
    Next
    convert = str
end function