vbscript - Replace all spaces

后端 未结 3 1647
自闭症患者
自闭症患者 2020-12-19 21:51

I have 6400+ records which I am looping through. For each of these: I check that the address is valid by testing it against something similar to what the Post Office uses (f

3条回答
  •  情歌与酒
    2020-12-19 22:35

    Personally I've just done a loop like this:

    Dim sLast
    Do
        sLast = strPostcode
        strPostcode = Replace(strPostcode, " ", "")
        If sLast = strPostcode Then Exit Do
    Loop
    

    However you may want to use a regular expression replace instead:

    Dim re : Set re = New RegExp
    re.Global = True
    re.Pattern = " +"  ' Match one or more spaces
    WScript.Echo re.Replace("OP6 6YH.", "")
    WScript.Echo re.Replace("OP6  6YH.", "")
    WScript.Echo re.Replace("O  P   6       6    Y     H.", "")
    Set re = Nothing
    

    The output of the latter is:

    D:\Development>cscript replace.vbs
    OP66YH.
    OP66YH.
    OP66YH.
    D:\Development> 
    

提交回复
热议问题