I have an equation stored in my table. I collect one equation at a time and want to replace all the operators with some other symbol.
Input line: (N_100-(6858)*(6858)*N_100/0_2)%N_35
Operators or patterns: (+, -, *, /, %, (, ))
Spare character: ~
Output line: ~N_100~~6858~~~6858~~N_100~0_2~~N_35
I tried the following query using Nested REPLACE functions and got the desired result:
DECLARE @NEWSTRING VARCHAR(100) SET @NEWSTRING = '(N_100-(6858)*(6858)*N_100/0_2)%N_35' ; SELECT @NEWSTRING = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @NEWSTRING, '+', '~'), '-', '~'), '*', '~'), '/', '~') , '%', '~'), '(', '~'), ')', '~') PRINT @NEWSTRING
Output: ~N_100~~6858~~~6858~~N_100~0_2~~N_35
How can I replace all operators without using the nested replacement functions?