Hi SudipBhatt,
thanks for the question that allows you to explain.
I hope I can explain how this works with an example.
Consider this code:
declare @s varchar(max)
declare @s1 varchar(max)
declare @s2 varchar(max)
declare @s3 varchar(max)
set @s = 'Alz''''heimer''''s Dis''''eas''''e (AD)'
-- First step
select @s1 = replace(@s, '''', '+-');
-- Second step
select @s2 = replace(@s1, '-+' , '');
-- third step
select @s3 = replace(@s2, '+-', '''');
select 'Original string: ' + @s
union all
select 'First step: ' + @s1
union all
select 'Second step: ' + @s2
union all
select 'Third step: ' + @s3
In it this happens:
a) Original string
Alz''heimer''s Dis''eas''e (AD)
b) Replaces each ' with +-
Alz+-+-heimer+-+-s Dis+-+-eas+-+-e (AD)
c) Removes any -+
In this way there will remain as many +- as the single quotes are
Alz+-heimer+-s Dis+-eas+-e (AD)
-- Finally, therefore, just replace each sequence +- with '
Alz'heimer's Dis'eas'e (AD)
The + and - signs are not magic symbols, but only placeholders for the purpose of making the game.
You can choose any other pair of symbols; what matters is that these characters must not be in the string.
Although I am fascinating, I do not like this technique and I always prefer to solve problems in a clear and easy to read way. This is for the benefit of clarity, scalability and code sharing.
Sorry if I wasn't clear, but I use the google translator to be able to write in English!