I executed following query and for some reason its not replacing new line character in database . It says Rows matched 1 but no change . What can be wrong ?
mysql> UPDATE aboutme SET abouttext=REPLACE(abouttext,'\\n','') WHERE userid='5099a95cd944b8.22468149'; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0
The Trim() function is used to remove new line characters from data rows in MySQL.
SELECT * FROM mytable WHERE mycolumn REGEXP "\r\n"; Hi Tim, thanks for answering!
-- Using both \r\n SELECT 'First line. \r\nSecond Line. ' AS 'New Line'; -- Using both \n SELECT 'First line.
In this case, we use replace function along with string to replace with, which in our case is an empty string. function removeLineBreaks(str) { return str. replace( /[\r\n]+/gm, "" ); } removeLineBreaks("Hello,\n Good Afternoon.
You can match a newline character using \n
, not \\n
.
Code:
UPDATE aboutme SET abouttext=REPLACE(abouttext,'\n','') WHERE userid='5099a95cd944b8.22468149';
If \n
does not work as in my case, the following worked \r\n
UPDATE aboutme SET abouttext=REPLACE(abouttext,'\r\n','') WHERE userid='5099a95cd944b8.22468149';
In my case it has been a web application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With