作者在 2021-04-20 20:00:37 发布以下内容
来源:https://bbs.csdn.net/topics/390991766
作者:回马枪
Clear
? UrlEncode(' test,这是一个测试', .F.) && .F. --> "+", .F. --> "%20"
Function UrlEncode(tcString, tlNoPlus)
Local lcReturn, lcChar, lnCounter
m.lcReturn=""
For m.lnCounter = 1 To Len(m.tcString)
m.lcChar = Substr(m.tcString, m.lnCounter, 1)
If Atc(m.lcChar,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") > 0
m.lcReturn = m.lcReturn + m.lcChar
Loop
Endif
If Asc(m.lcChar) = 32 And !m.tlNoPlus
m.lcReturn = m.lcReturn + "+"
Loop
Endif
m.lcReturn = m.lcReturn + "%" + Right(Transform(Asc(m.lcChar),"@0"),2)
Endfor
Return m.lcReturn
Endfunc