How to write \ simbols to mysql?
#1

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

You can replace '\n' to | before saving into database or other two symbols
Reply
#3

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

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

Код:
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?
Reply
#6

Ah '\\'
Reply
#7

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

PHP код:
new string[100] = "Hello|n world[...]";
new 
output[100];
format(outputsizeof(output), "%s"ReplaceNewline(string));
SendPlayerDialog(playeridDIALOG_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",""); 
Reply
#9

Quote:
Originally Posted by Mencent
Посмотреть сообщение
PHP код:
new string[100] = "Hello|n world[...]";
new 
output[100];
format(outputsizeof(output), "%s"ReplaceNewline(string));
SendPlayerDialog(playeridDIALOG_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;
}
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)