0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

EncodeURL メモ

Last updated at Posted at 2020-06-13

#EncodeURL:Excel
workSheet : EncodeURL("たくわん和尚")
マクロ : Application.WorksheetFunction.EncodeURL("たくわん和尚")

#EncodeURL:VBScript

EncodeURL
'==================================================
' 64bit環境では、CreateObject("ScriptControl")が効かない為でした。32bit仕様で動かす。
'x:\>C:\Windows\SysWOW64\cscript test.vbs
'==================================================

WScript.Echo fnURLENCODE2013("たくわん和尚")
WScript.Echo UrlEncodeUtf8("たくわん和尚")
WScript.Echo URLDecodeUTF8(UrlEncodeUtf8("たくわん和尚"))

'==================================================
'fnURLENCODE2013: 文字列をUTF-8でエンコードするFunction
'たくわん和尚 -> %E3%81%9F%E3%81%8F%E3%82%8F%E3%82%93%E5%92%8C%E5%B0%9A
'==================================================
'strSource: 元の文字列
'返り値: エンコードされた文字列
'==================================================
Function fnURLENCODE2013(str)
    Dim xlApp: Set xlApp = CreateObject("Excel.application")
    fnURLENCODE2013 = xlApp.WorksheetFunction.EncodeURL(str)
    Set xlApp = Nothing
End Function

'==================================================
'UrlEncodeUtf8: 文字列をUTF-8でエンコードするFunction
'たくわん和尚 -> %E3%81%9F%E3%81%8F%E3%82%8F%E3%82%93%E5%92%8C%E5%B0%9A
'==================================================
'strSource: 元の文字列
'返り値: エンコードされた文字列
'==================================================
Public Function UrlEncodeUtf8(strSource)
    Dim objSC
    Set objSC = CreateObject("ScriptControl")
    objSC.Language = "Jscript"
    UrlEncodeUtf8 = objSC.CodeObject.encodeURIComponent(strSource)
    Set objSC = Nothing
End Function

'==================================================
'UrlDecodeUtf8: 文字列をUTF-8でデコードするFunction
'%E3%81%9F%E3%81%8F%E3%82%8F%E3%82%93%E5%92%8C%E5%B0%9A -> たくわん和尚
'==================================================
'strSource: 元の文字列
'返り値: エンコードされた文字列
'==================================================
Public Function URLDecodeUTF8(strSource)
    Dim objSC
    Set objSC = CreateObject("ScriptControl")
    objSC.Language = "Jscript"
    URLDecodeUTF8 = objSC.CodeObject.decodeURIComponent(strSource)
    Set objSC = Nothing
End Function

物忘れ防止 VBScript Encode.vbs

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?