Special Characters including Space RRS feed

  • Question

  • User-797751191 posted


      I want to remove special characters from a string and then compare with other values


    Friday, December 13, 2019 5:45 AM

All replies

  • User364663285 posted

    Try with Replace like

    SELECT REPLACE('SQL Tutorial', 'T', 'M');

    Friday, December 13, 2019 8:25 AM
  • User288213138 posted

    Hi jsshivalik,


    I want to remove special characters from a string

    When you ask a question, please describe your requirement in detail.

    Do you want to remove special characters from strings in the sql, or is it just a C # question?

    If in the sql, you can try to use the REPLACE() Function.

    DECLARE @email VARCHAR(55) = 'johndoe@a!b#c.com$';
    SELECT REPLACE(REPLACE(REPLACE(@email, '!', ''), '#', ''), '$', '');

    If in the C#, you can try to use Regex.Replace() function.

    Regex.Replace("sam%&wu", @"[^0-9a-zA-Z]+", "");


    compare with other values

    How do you want to compare these two values?

    In the Sql. The STRCMP() function compares two strings. If string1 = string2, this function returns 0 If string1 < string2, this function returns -1, else returns 1.

    More information about STRCMP() function you can refer to below link:


    Best regards,


    Monday, December 16, 2019 2:31 AM