Un-escaping string
#1

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.
Reply
#2

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)
Reply
#3

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

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));
Reply
#5

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)