Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save toronya/4592532 to your computer and use it in GitHub Desktop.
Save toronya/4592532 to your computer and use it in GitHub Desktop.
Decoding URL Query String Parameters by Lotus Notes Agent Script.
Option Declare
'#-------------------------------------------------------#
'# Decode URL Query String Parameters by Lotus Notes Agent Script.
'#
'# ex. http://example.com/test.nsf/agentname?openagent&title=%E3%83%88%E3%83%83%E3%83%97%E3%83%9A%E3%83%BC%E3%82%B8
'# => arg_decoded = "トップページ"
'#-------------------------------------------------------#
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim arg As String
Dim arg_decoded As String
Dim url_title As String
Dim to_encode As String
Set db = session.CurrentDatabase
arg = session.DocumentContext.Query_String_Decoded(0)
url_title = GetParmValue(arg , "title")
'# if you need encode to output
to_encode = "Shift_JIS"
arg_decoded = URLDecode(arg,to_encode)
print arg_decoded
End Sub
'#-------------------------------------------------------#
'# Decode URL Query String Parameters
'#-------------------------------------------------------#
Function URLDecode(source As String, encodetype As String) As String
Dim macro As Variant
Dim tmp As Variant
macro = "@URLDecode(""" & encodetype & """;""" & source & """)"
tmp = Evaluate(macro)
URLDecode = tmp(0)
End Function
'#-------------------------------------------------------#
'# choice key,value from URL Query String Parameters
'#
'# ex. url : http://example.com/test.nsf/agentname?openagent&id=4&title=TITLE
'# GetParmValue(url,"id") => "4"
'# GetParmValue(url,"title") => "TITLE"
'#-------------------------------------------------------#
Function GetParmValue(arg , key)
Dim query_arr As Variant
query_arr = Split(arg,"&")
Dim q As Integer
For q = Lbound(query_arr) To Ubound(query_arr)
Dim r_arr As Variant
r_arr = Split ( query_arr(q) , "=") '# => ["id","4"]
If r_arr(0) = key Then
GetParmValue = r_arr(1) '# => ,"4"
Exit For
End If
Next
End Function
@EwenH
Copy link

EwenH commented Aug 19, 2013

Excellent code,
You may want to consider declaring q in GetParamValue for those who prefer their code declared explicitly.

@toronya
Copy link
Author

toronya commented Apr 22, 2014

Thanks, Update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment