Removing Multiple Extra Spaces or White Spaces Into Single Space using Regular Expressions in Reporting Services
While I was developing a MS SQL Server Reporting Services report, I had to remove the extra white spaces using Regular Expressions.
Here is the copy - paste source code of the VB function RemoveExtraSpaces I had used in the Reporting Services report Custome Code section.
Here is a preview output from the sample reporting setvices report I had developed using MSSQLServer 2005 Reporting Services using the Custom Code function RemoveExtraSpaces:
You can use this Custom Code function RemoveExtraSpaces by using the following expression in your Reporting Services reports Layout similar code shown below:
I had used the below VB code for defining the Regular Expressions class Regex;
The regular expression used for removing the extra white spaces like extra spaces or multiple spaces is "\s+".
The below code replaces the multiple spaces characters with single space character and trims for the leading and trailing space characters using the Trim() function.