SQL Server, T-SQL, ASP.NET, Javascript, SAP, ABAP Programming

Kodyaz Development Resources

Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.
Welcome to Kodyaz Development Resources Sign in | Join | Help




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.

Public Function RemoveExtraSpaces(input_text As String) As String

Dim rsRegEx as System.Text.RegularExpressions.Regex
rsRegEx = new System.Text.RegularExpressions.Regex("\s+")

return rsRegEx.Replace(input_text, " ").Trim()

End Function

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:

remove extra white spaces in reporting services using custom code

You can use this Custom Code function RemoveExtraSpaces by using the following expression in your Reporting Services reports Layout similar code shown below:

= Code.RemoveExtraSpaces(" Business Phone Ext")




I had used the below VB code for defining the Regular Expressions class Regex;

Dim rsRegEx as System.Text.RegularExpressions.Regex
rsRegEx = new System.Text.RegularExpressions.Regex("\s+")

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.

return rsRegEx.Replace(input_text, " ").Trim()





SSRS-Reporting Services

SQL Server Articles

Reporting Services Blog

SQL Server Reporting Services Forums

SQL Blog

Certification Exams Blog



Free Exam Vouchers












Copyright © 2004 - 2010 Eralper Yilmaz. All rights reserved.
Powered by Community Server, by Telligent Systems