Skip to content

Instantly share code, notes, and snippets.

@ndthanh
Created January 12, 2018 17:32
Show Gist options
  • Save ndthanh/18d5cd144a33d87b14e76c16df5939ee to your computer and use it in GitHub Desktop.
Save ndthanh/18d5cd144a33d87b14e76c16df5939ee to your computer and use it in GitHub Desktop.
Public Function FormatString(ByVal sFormat As String, _
ParamArray arg() As Variant)
Dim idx As Integer
For idx = LBound(arg) To UBound(arg)
sFormat = Replace(sFormat, "{" & idx & "}", arg(idx))
Next idx
FormatString = sFormat
End Function
Sub UnitTest()
Dim strURL As String, strUser As String, strToken As String, strOp As String
strUser = "heo"
strToken = "930kdoakdlcaj"
strOp = "topup"
strURL = "https://hocexcel.online/register.js?username={0}&token={1}&operation={2}"
'strURL= "https://hocexcel.online/register.js?username=" & struser & "&token=" & strToken & "&operation=" & strOp
Debug.Print FormatString(strURL, strUser, strToken, strOp)
'https://hocexcel.online/register.js?username=heo&token=930kdoakdlcaj&operation=topup
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment