I have an equation stored in my table. I am fetching one equation at a time and want to replace all the operators with any other character.
Input String: (N_100-(6858)*(6858)*N_100/0_2)%N_35
Operators or patterns: (+, -, *, /, %, (, ))
Replacement character: ~
Output String: ~N_100~~6858~~~6858~~N_100~0_2~~N_35
I had tried below query with Nested REPLACE Functions and I got desired output:
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 the operators without using nested replace functions?