Technical Article

Remove multiple whitespace from a string (alternat

,

Here's an alternate way of removing multiple white spaces by using the REPLACE command.

CREATE  FUNCTION dbo.udfCleanString (@string VARCHAR(50))  
RETURNS VARCHAR(50)
AS
BEGIN 
SET @string = LTRIM(RTRIM( @string ))

WHILE CHARINDEX('  ', @string ) > 1
SET @string = REPLACE(@string, '  ', ' ')

RETURN @string
END

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating