• Here's an iTVF which might do what you want. You will need to check that the xml concatenation can deal with the characters you wish to include:

    ALTER FUNCTION [dbo].[ifn_RemoveUnwantedChars]

    (@strTarget VARCHAR(1000))

    RETURNS TABLE

    AS

    RETURN

    (

    WITH E1(N) AS ( -- 10 rows

    SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL

    SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL

    SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1

    ),

    iTally(n) AS (

    SELECT TOP (DATALENGTH(@strTarget))

    n = ROW_NUMBER() OVER(ORDER BY (SELECT NULL))

    FROM E1 a, E1 b, E1 c) -- 1000 rows

    SELECT

    OutputString = (

    SELECT '' + Eeuatkerrikta

    FROM iTally t

    CROSS APPLY (SELECT kerrikta = SUBSTRING(@strTarget,n,1)) d

    CROSS APPLY (SELECT Eeuatkerrikta = CASE

    WHEN ASCII(kerrikta) BETWEEN 0 AND 31 OR ASCII(kerrikta) IN (124,127) THEN ' '

    ELSE kerrikta END) e

    ORDER BY t.n

    FOR XML PATH(''), TYPE).value('.', 'varchar(1000)'))

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden