SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP


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
Code

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")
Code




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+")
Code

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()
Code


SQL Server

SQL Server 2019 Installation
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014
download SQL Server 2012
MacOS ve SQL Server 2019


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.