B4J Question [BANano]: [SOLVED] How to UTF8 encode strings for URL querystrings?

Discussion in 'B4J Questions' started by Mashiane, Apr 7, 2019.

Tags:
  1. Mashiane

    Mashiane Expert Licensed User

    Hi there

    In my b4a I use this sub to convert a map to a querystring that I eventually pass to HTTP to execute a PHP request from my MySQL db.

    Is there a method to encode strings in banano, for example, Im using stringutils for this..

    Code:
    'convert a map to a querystring
    Sub Map2QueryString(sm As MapAs String
        
    ' convert a map to a querystring string
        Dim SU As StringUtils
        
    Dim iCnt As Int
        
    Dim iTot As Int
        
    Dim sb As StringBuilder
        
    Dim mValue As String
        sb.Initialize
        
        
    ' get size of map
        iTot = sm.Size - 1
        iCnt = 
    0
        
    For Each mKey As String In sm.Keys
            mValue = sm.Getdefault(mKey,
    "")
            mValue = mValue.trim
            mValue = SU.EncodeUrl(mValue, 
    "UTF8")
            mKey = mKey.Trim
            
    If mKey.EndsWith("=") = False Then mKey = mKey & "="
            sb.Append(mKey).Append(mValue)
            
    If iCnt < iTot Then sb.Append("&")
            iCnt = iCnt + 
    1
        
    Next
        
    Return sb.ToString
    End Sub
    Thanks in advance...
     
  2. Mashiane

    Mashiane Expert Licensed User

    Solution:

    Code:
    BANano.EncodeURI(mValue)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice