以下是引用sdta在2023-5-8 13:17:04的发言:
对楼主是否有帮助
* 只对双字节字符编(解)码_UTF8编码;
* 还有一种常用的GB2312编码,方法逐个取双字节符用 TRANSFORM() 进行转换。
* cc = RIGHT(TRANSFORM(ASC("中"), "@0"), 4)
* 还原:CHR(EVALUATE("0x" + cc))
CLEAR
lcPath = JUSTPATH(SYS(16))
lc = "西安音12乐学院"
? lc
\*****************************************
\ URL编码
? UrlEncode(lc)
\ URL解码
? UrlDecode(UrlEncode(lc))
? UrlDecode("%E8%A5%BF%E5%AE%89%E9%9F%B3%E4%B9%90%E5%AD%A6%E9%99%A2")
STRTOFILE(UrlEncode(lc), "BM.TXT")
MODIFY FILE BM.TXT
* URL编码
FUNCTION UrlEncode(cStr)
LOCAL lcValue, lcEnStr, lc, lnJ, lnK
lcEnStr = ""
FOR lnJ = 1 TO LEN(cStr)
lc = SUBSTR(cStr, lnJ, 1)
IF ISLEADBYTE(lc)
lc = SUBSTR(cStr, lnJ, 2)
lnJ = lnJ + 1
lcValue = STRCONV(STRCONV(lc, 9), 15)
FOR lnK = 1 TO LEN(lcValue) STEP 2
lcEnStr = lcEnStr + "%" + SUBSTR(lcValue, lnK, 2)
ENDFOR
ELSE
lcEnStr = lcEnStr + lc
ENDIF
ENDFOR
RETURN lcEnStr
ENDFUNC
* URL解码
FUNCTION UrlDecode(cEncode)
LOCAL lcStr, lnJ, laCode[1]
lcStr = ""
FOR lnJ = 1 TO ALINES(laCode, cEncode, 5, "%") STEP 3
lcStr = lcStr + STRCONV(STRCONV(laCode[lnJ] + laCode[lnJ + 1] + LEFT(laCode[lnJ + 2], 2), 16), 11) + SUBSTR(laCode[lnJ + 2], 3)
ENDFOR
RETURN lcStr
ENDFUNC
iOK=AT("%",cEncode)
lcStr = LEFT(cEncode,iOK-1)
cEncode=SUBSTR(cEncode,AT("%",cEncode))