SA-MP Forums Archive
Un-escaping string - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Un-escaping string (/showthread.php?tid=443247)



Un-escaping string - kristo - 11.06.2013

Yesterday I made a /setgroupname command and when I was testing it, I renamed one group into "Sheriff's Department" and it caused a MySQL error because of the ' in it. So I had to escape the string. Now when I restart the server and the groups load, the name will be shown with a backslash ("Sheriff\'s Department"). How could I remove it? Just a basic example would be fine.

Sorry for my bad English.


Re: Un-escaping string - Sascha - 11.06.2013

what about checking for a slash and then replacing it?
like
Код:
new pos = strfind(string, "\\", true, 0);
strdel(string, pos, pos);
maybe use a loop that checks for the backslash more often incase there are more than 1 in the string...
(the \\ because a \" would cause a " not to be detected as a ":P.. so I guess \\ would work)


Re: Un-escaping string - Vince - 11.06.2013

That's not a default behavior. What did you use to escape the strings?


Re: Un-escaping string - Emmet_ - 11.06.2013

Quote:
Originally Posted by Sascha
Посмотреть сообщение
what about checking for a slash and then replacing it?
like
Код:
new pos = strfind(string, "\\", true, 0);
strdel(string, pos, pos);
maybe use a loop that checks for the backslash more often incase there are more than 1 in the string...
(the \\ because a \" would cause a " not to be detected as a ":P.. so I guess \\ would work)
What if there is more than 1 backslash?

To OP: Try this, I've copied it out of my GM and it works fine.

pawn Код:
stock RemoveBackslashes(const string[])
{
    new ret[256];
    memcpy(ret, string, _, 1024, sizeof(ret));
    for (new i = 0, length = strlen(ret); i < length; i ++)
    {
        if (ret[i] == '\\')
        {
            strdel(ret, i, i + 1);
            continue;
        }
    }
    return ret;
}
Example:

pawn Код:
printf("%s", RemoveBackslashes(string));



Re: Un-escaping string - Sascha - 11.06.2013

Quote:
Originally Posted by Sascha
Посмотреть сообщение
maybe use a loop that checks for the backslash more often incase there are more than 1 in the string...
I already mentioned that loop for more backslashes in the string