幫一客戶修改VB6程式,需要對一個http url進行編碼操作,也就是url encode。經過一番研究,決定用插件實作。
1. 安裝插件Chilkat
Chilkat Full-Version Software Components Downloads (chilkatsoft.com)
選擇 Chilkat ActiveX Components
win32和x64的版本,實測我的Win10 x64系統用win32版本是有效的。
2. 添加引用
工程 > 引用,勾選 Chilkat ActiveX v9.5.0, 确定
3. 代碼
Public Function URLEncodeNew(ByVal strContent As String) As String
Dim strObj As New CkString
strObj.str = strContent
Dim str As String
str = strObj.GetEncoded("url", "utf-8") 'utf-8
str = Replace(str, ",", "%2C") '處理逗号
URLEncodeNew = str
End Function