Search code examples
reporting-servicesexpressioncarriage-return

Remove Blank Lines from String SSRS


I have a field in my SSRS report that has multiple carriage returns, for example:

 First, get materials



 Next, glue them all together

 Last, let dry for two hours

All six lines are in in the one field, its not 7 rows. I know I can replace/remove the carriage returns, but what I am really looking for is to be able to just remove the blank lines. I would still want to keep the carriage returns on the lines that have text, like this:

 First, get materials
 Next, glue them all together
 Last, let dry for two hours

I greatly appreciate any help on this.

Thanks!


Solution

  • I think your problem is that multiple return carriage/new line characters could be present in each line, while your expected result is divide each line by only one return carriage or new line character.

    I think it can be avoided using Regex replace method (Yes, you can use Regex in SSRS).

    If you are sure your source is generating the new line using carriage return you can use:

    =System.Text.RegularExpressions.Regex.Replace(Fields!MultilineText.Value,
    "\r\r+",Environment.NewLine) 
    

    Otherwise if your source is generating the next line via new line character (code 10 in ascii) you should use:

    =System.Text.RegularExpressions.Regex.Replace(Fields!MultilineText.Value,
    "\n\n+",Environment.NewLine)
    

    Note most Windows systems use \r\n to determine an end of line, replace accordingly to your environment.

    UPDATE:

    =System.Text.RegularExpressions.Regex.Replace(Fields!MultilineText.Value,
    "\r\n[\r\n]+",Environment.NewLine)
    

    Let me know if this helps.