Ask Your Question
1

After importing, the character string "\n" is being eliminated from the MySQL database. How can this be prevented?

asked 2023-04-30 19:56:37 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-04-30 20:00:02 +0000

plato gravatar image

One solution is to use the MySQL function "CHAR()" to represent the "\n" as a character instead of a line break. For example, if you want to store the string "Hello\nWorld" with the line break intact, you can use the following SQL command:

INSERT INTO tablename (columnname) VALUES ('Hello' + CHAR(10) + 'World');

The CHAR(10) function represents the line break as a character and will preserve it in the database. When retrieving the data, you can use the MySQL function "REPLACE()" to replace the character back into a line break, if needed.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-04-30 19:56:37 +0000

Seen: 9 times

Last updated: Apr 30 '23