Technical Article

Removing double spaces in a string

,

Removes double spaces in a string, leaving all words seperated by a single space. Run in Query Analyzer.

/*
Removing double spaces
*/DECLARE @s VARCHAR(500)
SET @s = 'Typical      mainframe     data'
WHILE CHARINDEX(SPACE(2), @s) > 0 
SET @s = REPLACE(@s, SPACE(2), SPACE(1))

/*
Do something with the result
*/PRINT @s

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating