How to write \ simbols to mysql? -
StRaphael - 18.11.2018
Hello, I am trying to add a large message to my mysql database.
My code looks like this:
format(string, sizeof(string), "Hello,\n you have more %d days to pay[...]", x,y,z);
So my question is how to add "\" d symbols to database?I mean when I run the code in database appears just with paragraph, like that:
Hello,
you have more[...]
And I want that:
Hello,\n you have more[...]
Any solution?Thanks.
I am using MySQL R33
Re: How to write \ simbols to mysql? -
Jefff - 18.11.2018
You can replace '\n' to | before saving into database or other two symbols
Re: How to write \ simbols to mysql? -
StRaphael - 18.11.2018
Quote:
Originally Posted by Jefff
You can replace '\n' to | before saving into database
|
You mean like that?
format(string, sizeof(string), "Hello,|n you have x...",x,y,z);
I have to mention that this message will be shown in a text box, like an /email command that read the message from database, and that's why I need "\" symbol.
Re: How to write \ simbols to mysql? -
Jefff - 18.11.2018
pawn Код:
ReplaceNewline(string[], bool:save = true)
{
new charr = (save) ? '\' : '|';
for(new i = strlen(string) - 1; i > -1; i--)
if(string[i] == charr && string[i + 1] == 'n')
string[i] = (save) ? '|' : '\';
}
and with saving
format(string, sizeof(string), "Hello,\n you have x...",x,y,z);
ShowDialog
ReplaceNewline(string);
INSERT INTO .... string
in reading set save to false
Re: How to write \ simbols to mysql? -
StRaphael - 18.11.2018
Код:
ReplaceNewline(string[], bool:save = true)
{
new charr = (save) ? '\' : '|'; //error 027: invalid character constant
for(new i = strlen(string) - 1; i > -1; i--)
if(string[i] == charr && string[i + 1] == 'n')
string[i] = (save) ? '|' : '\'; //error 027: invalid character constant
}
How can I resolve those errors?
Re: How to write \ simbols to mysql? -
Jefff - 18.11.2018
Ah '\\'
Re: How to write \ simbols to mysql? -
StRaphael - 19.11.2018
Quote:
Originally Posted by Jefff
Ah '\\'
|
Still dosn't work...
Isn't that the correct use of this function?
Код HTML:
new string[100] = "Hello|n world[...]";
new output[100];
format(output, sizeof(output), "%s", ReplaceNewline(string));
ShowPlayerDialog(playerid, DIALOG_STYLE_MSGBOX, "Title", output, "Ok", "");
I mean when I run the code is dosn't do anything...
Re: How to write \ simbols to mysql? -
Mencent - 19.11.2018
PHP код:
new string[100] = "Hello|n world[...]";
new output[100];
format(output, sizeof(output), "%s", ReplaceNewline(string));
SendPlayerDialog(playerid, DIALOG_STYLE_MSGBOX, "Title", output, "Ok", "");
It's wrong. You have to write it like this:
PHP код:
new string[100] = "Hello|n world[...]";
ReplaceNewLine(string);
ShowPlayerDialog(playerid,DIALOG_STYLE_MSGBOX,"Title",string,"Ok","");
Re: How to write \ simbols to mysql? -
StRaphael - 19.11.2018
Quote:
Originally Posted by Mencent
PHP код:
new string[100] = "Hello|n world[...]";
new output[100];
format(output, sizeof(output), "%s", ReplaceNewline(string));
SendPlayerDialog(playerid, DIALOG_STYLE_MSGBOX, "Title", output, "Ok", "");
It's wrong. You have to write it like this:
PHP код:
new string[100] = "Hello|n world[...]";
ReplaceNewLine(string);
ShowPlayerDialog(playerid,DIALOG_STYLE_MSGBOX,"Title",string,"Ok","");
|
Still do nothing

Command:
Код HTML:
CMD:showtestdialog(playerid, params[])
{
new string[100] = "Hello|n world[...]";
ReplaceNewline(string);
ShowPlayerDialog(playerid, DIALOG_CANCELJOB, DIALOG_STYLE_MSGBOX, "Title", string, "Ok", "");
return 1;
}
Re: How to write \ simbols to mysql? -
Mencent - 19.11.2018
Eh, I think that function won't do what you want.
Try this:
PHP код:
ReplaceNewString(string[])
{
for(new i;strlen(string) < i;i++)
{
if(string[i] == '|' && string[i+1] == 'n')string[i] = '\';
else if(string[i] == '\' && string[i+1] == 'n')string[i] = '|';
}
}
So you can convert "\n" into "|n" and you can save this into your mysql database. When you read this and save it in a string you convert it to "\n" back.