I have to make a difficult word processing. How can I change dynamically as the following example?
Example: /hello/ baby /deneme/ /hello2/
Output: (/hello/) baby (/deneme/) (/hello2/)
I have to make a difficult word processing. How can I change dynamically as the following example?
Example: /hello/ baby /deneme/ /hello2/
Output: (/hello/) baby (/deneme/) (/hello2/)
 
    
    This is a pretty rudimentary solution, but it works for the case you've given (SQL Fiddle here):
SELECT
  in_str,
  (
    -- If the string starts with '/', prepend '('
    CASE WHEN in_str LIKE '/%' THEN '(' ELSE '' END
    -- Replace / after a space with (/
    + REPLACE(
        -- Replace / before by a space with /)
        REPLACE( in_str, ' /', ' (/' ),
        '/ ', '/) '
      )
    -- If the string ends with '/', append ')'
    + CASE WHEN in_str LIKE '%/' THEN ')' ELSE '' END
  ) AS out_str
FROM table1;
If table1 has the following in_str values this will give you the corresponding out_str values:
in_str                    out_str
------------------------  ------------------------------
/one/ two /three/ /four/  (/one/) two (/three/) (/four/)
one /two/ /three/         one (/two/) (/three/)
/one/ /two/ three         (/one/) (/two/) three
//one / // two/ /         (//one (/) (//) two/) (/)
I've included the last one to demonstrate some edge cases. Also note that this only handles / characters immediately followed by a space or the beginning or end of the string. Other whitespace characters like newlines and tabs aren't handled. For example, if you had a string like this (where ⏎ indicates a newline and ⇒ a tab):
/one/⇒/two/⏎
/three/⏎
...the output you would get is this:
(/one/⇒/two/⏎
/three/⏎
You could handle these scenarios with additional REPLACE functions, but that's a rabbit hole you'll have to jump down yourself.
