Technical Article

Remove multiple whitespace from a string: revise

,

This is a re-written function that the idea got from yesterday's script. This function used a recursive call to simplify the script.

CREATE function cleanString2(@string varchar(50))
returns varchar(50)
AS
Begin
if charindex('  ', @string) = 0 return @string
set @string = replace(@string, '  ',' ')
while charindex('  ', @string) > 0
select @string = dbo.cleanString2(@string) --recursive call

return rtrim(ltrim(@string))
End

Rate

4 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

4 (1)

You rated this post out of 5. Change rating