here is a snippet of code i’ve been using to encode strings to be sent to a web server for processing. Its kinda along the same lines as the snippet above. I had trouble inserting data into a database and thought that it’d be just as easy to encode the string on the controller rather than muck around on the server side (and to ensure the url isn’t broken). although i am using with PAC Control, i can see no reason why it cannot be used with OptoControl also (I will be implementing on an M4 soon enough).
//ok very simple process here. we need to loop through each char in the string and if we find
//a character deemed as a reserved or unsafe character then
//we then insert into the string the encoded string (ie space would become %20).
//the string to be encoded is sToBeEncoded and the result goes into sEncodedString
sTempStr=""; //clear the temp string used to house the encoded string
intSubStrLen=0; //this is what position we start when disecting the string
for x = 0 to intStrLength step 1
intChar = GetNthCharacter(sToBeEncoded, x);
//other characters that can be included are: 123,124,125,92,94,126,91,93 and 96
GetSubstring(sToBeEncoded, intSubStrLen, x-intSubStrLen, subStr);
GetSubstring(sToBeEncoded, intSubStrLen, x-intSubStrLen, subStr); //get the string and append
example of where to use this would be if you needed to write string data to a database via a php script. i might have a string as follows: ‘here is my piece of code’. the result from running through the script would be ‘here%20is%20my%20piece%20of%20code’. url safe. only catch is that you don’t exceed the string width of the sEncodedString
hope this helps someone out there.