跳转到内容

编码指南/URL 编码

来自 Wikibooks,开放世界开放书籍

对字符串中的特殊字符进行编码,以便在 URL 中使用

VBScript 解决方案

[编辑 | 编辑源代码]
function URLEncode (sInput)
  if IsNull(sInput) then
    URLEncode = ""
    exit function
    end if
  URLEncode = sInput
  URLEncode = Replace(URLEncode, chr(0), "")
  URLEncode = Replace(URLEncode, "%", "%25")
  URLEncode = Replace(URLEncode, " ", "%20")
  URLEncode = Replace(URLEncode, """", "%22")
  URLEncode = Replace(URLEncode, "&", "%26")
  URLEncode = Replace(URLEncode, "'", "%27")
  URLEncode = Replace(URLEncode, "/", "%2F")
  URLEncode = Replace(URLEncode, "?", "%3F")
  URLEncode = Replace(URLEncode, "\", "%5C")
end function
function URLEncode (sInput)
  Escape(sInput)
end function
华夏公益教科书