Link to home
Start Free TrialLog in
Avatar of apedic
apedicFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to search a string in a mysql text field

Hello,

I need to search a string in a mysql text field that could contains newlines chars. Using the standard LIKE operator it does not work because the string searched is different from the text field as it contains newlines.

Here is an example:
select id from fb_posts where message like '%Fineco App. Tutti i servizi, in tutti i device. Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

the string could not be found because the text field is:

Fineco App. Tutti i servizi, in tutti i device.
Da dove preferite collegarvi?

https://welcome.fineco.it/bancaonline/extra/fineco-app

So I think there should be e method to search removing newline chars.

thank you
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Try
select id from fb_posts where message like '%Fineco App. Tutti i servizi, in tutti i device.\n Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

Open in new window

or
select id from fb_posts where message like '%Fineco App. Tutti i servizi, in tutti i device.\r\n Da dove preferite collegarvi? https://welcome.fineco.it/bancaonline/extra/fineco-app%'

Open in new window

if the text is from Windows.

HTH,
Dan
ASKER CERTIFIED SOLUTION
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of apedic

ASKER

thank you, works perfectly!
Glad I could help!