Here is some code of a script I wrote. It just takes in a string and replaces certain values with other values for URL building.
Now, this SCREAMS to me to use a map, but I really don't get how to use them, work with them or how to make one, for that matter. This sounds a bit way too n00bish, like, this guy should look it up! But even after taking a look in several scripts and in Veracity's tutorial, I'm still decently lost.
In a function like the above, how would a map work?
Also, would s = s.replace_string("?", "%3F"); work for implied parameters?
Thanks!
- MN
Code:
string messageReplace(string s)
{
s = replace_string(s, "%", "%25");
s = replace_string(s, "~", "%7E");
s = replace_string(s, "`", "%60");
s = replace_string(s, "!", "%21");
s = replace_string(s, "@", "%40");
s = replace_string(s, "#", "%23");
s = replace_string(s, "$", "%24");
s = replace_string(s, "^", "%5E");
s = replace_string(s, "&", "%26");
s = replace_string(s, "(", "%28");
s = replace_string(s, ")", "%29");
s = replace_string(s, "+", "%2B");
s = replace_string(s, "=", "%3D");
s = replace_string(s, "{", "%7B");
s = replace_string(s, "}", "%7D");
s = replace_string(s, "[", "%5B");
s = replace_string(s, "]", "%5D");
s = replace_string(s, "\\", "%5C");
s = replace_string(s, "|", "%7C");
s = replace_string(s, ":", "%3A");
s = replace_string(s, ";", "%3B");
s = replace_string(s, "\"", "%22");
s = replace_string(s, "\'", "%27");
s = replace_string(s, "<", "%3C");
s = replace_string(s, ">", "%3E");
s = replace_string(s, ",", "%2C");
s = replace_string(s, "/", "%2F");
s = replace_string(s, "?", "%3F");
return s;
}
Now, this SCREAMS to me to use a map, but I really don't get how to use them, work with them or how to make one, for that matter. This sounds a bit way too n00bish, like, this guy should look it up! But even after taking a look in several scripts and in Veracity's tutorial, I'm still decently lost.
In a function like the above, how would a map work?
Also, would s = s.replace_string("?", "%3F"); work for implied parameters?
Thanks!
- MN