一个半角=>全角的函数,仅限于chr(33)-chr(126),vbs版 效率不是很高,reg对象的replace方法使用反相引用的结果不能放到函数里(造诣不高),我这里就用了execute<SCRIPT LANGUAGE="VbScript"> str = "1新浪网!@#程序员_+}{:><" alert str&vbcrlf&b2s(str)function b2s(strng) Dim regEx,Matches,Match Set regEx = New regExp regEx.Pattern = "[\x21-\x7e]" regEx.IgnoreCase = False regEx.Global = True Set Matches = regEx.Execute(strng) For Each Match In Matches strng = replace(strng,Match.value,chrw(asc(Match.value)+65248)) Next Set Matches = nothing Set regEx = nothing b2s = strng end function </SCRIPT>
效率不是很高,reg对象的replace方法使用反相引用的结果不能放到函数里(造诣不高),我这里就用了execute<SCRIPT LANGUAGE="VbScript">
str = "1新浪网!@#程序员_+}{:><"
alert str&vbcrlf&b2s(str)function b2s(strng)
Dim regEx,Matches,Match
Set regEx = New regExp
regEx.Pattern = "[\x21-\x7e]"
regEx.IgnoreCase = False
regEx.Global = True
Set Matches = regEx.Execute(strng)
For Each Match In Matches
strng = replace(strng,Match.value,chrw(asc(Match.value)+65248))
Next
Set Matches = nothing
Set regEx = nothing
b2s = strng
end function
</SCRIPT>