I am submitting information using network.request and GET
\_G.theNetworkRequest = network.request( requestString, "GET", serverCommunicate.networkListener,params );
the requestString could look like this: https:\www.somewhere.com?description=mytext
The requestString contains information entered by the user, and I need to find a way to handle special characters that are not causing the request string to be malformed.
if the description, instead of “mytext” contains characters like ^ or , the URL is malformed.
Therefore I replace these characters with e.g. “-!!!BACKSLASH!!!-” and when read the data that is returned from the server I want to replace “-!!!BACKSLASH!!!-” with “” again.
The problem is the string.gsub() function.
Here is my code:
theDescription = "some text -!!!BACKSLASH!!!- and some more text" local lookfor = "-!!!BACKSLASH!!!-"; local replacewith = '\\'; theDescription = string.gsub(theDescription,lookfor,replacewith);
- One problem is that theDescription after this substitution contains the text:
“some text \!- and some more text”
in other words, the gsub() functions does not replace the whole string, but leaves “!-” at the end of it.
(I have tried replacewith = “%\”, but it gives the same result)
- The other problem is that I cannot set the variable replacewith = “” (or “%”), because then the IDE (ZeroBrane Studios) tells me that “” is an unfinished string and will not comply the code.
