1

我在 vbscript 上有以下功能:

Function HTMLEncode(sText) 
    Dim regEx 
    Dim matches 
    Dim match 


    sText = Replace(sText, Chr(34), """) 
    sText = Replace(sText, Chr(60)  , "<") 
    sText = Replace(sText, Chr(62)  , ">") 
    sText = Replace(sText, Chr(38), "&") 
    sText = Replace(sText, Chr(32), " ") 


    Set regEx= New RegExp 

    With regEx 
     .Pattern = "&#(\d+);" 'Match html unicode escapes 
     .Global = True 
    End With 

    Set matches = regEx.Execute(sText) 

    'Iterate over matches 
    For Each match in matches 
        'For each unicode match, replace the whole match, with the ChrW of the digits. 


         sText = Replace(sText, ChrW(match.SubMatches(0)), match.Value) 
    Next 

    HTMLEncode = sText 
End Function 

但是,这不会对空间进行编码。当我输入 >、<、" 和 & 时,它们会被编码。但是当我输入空格时,它不会被编码。它会,但是当我输入多个空格时它会被编码,例如:

"thishas4spaces    word"

除最后一个空格外,前三个被编码。所以它是这样的:

"thishas4spaces&nbsp;&nbsp;&nbsp; word"

知道为什么吗?请帮忙。语言是vbscript

4

0 回答 0