Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql: replace \ (backslash) in strings

I am having the following problem:

I have a table T which has a column Name with names. The names have the following structure:

A\\B\C

You can create on yourself like this:

create table T ( Name varchar(10));

insert into T values ('A\\\\B\\C');

select * from T;

Now if I do this:

select Name from T where Name = 'A\\B\C';

That doesn't work, I need to escape the \ (backslash):

select Name from T where Name = 'A\\\\B\\C';

Fine.

But how do I do this automatically to a string Name?

Something like the following won't do it:

select replace('A\\B\C', '\\', '\\\\');

I get: A\\\BC

Any suggestions?

Many thanks in advance.

like image 705
user1316758 Avatar asked Apr 08 '12 00:04

user1316758


1 Answers

You have to use "verbatim string".After using that string your Replace function will look like this

Replace(@"\", @"\\")

I hope it will help for you.

like image 139
Rahul Avatar answered Nov 15 '22 22:11

Rahul