Reputation: 1501
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!
Upvotes: 3
Views: 3652
Reputation: 1460
I got a good answer that I just figured out. My Address2 (second line of an address) is not always there in all the rows. So I was able to use a conditional to put a vbCrlf in or put Nothing in if there was no value in Address2.
So now, each concatenated line stacks up nicely without empty rows if there is no Address2. Probably could do this with Environment.Newline instead of the vbCurliff.
=Trim(Fields!IPA_Addr1.Value) & IIF(LEN(Trim(Fields!IPA_Addr2.Value)) > 0, vbCrLf, Nothing) & Trim(Fields!IPA_Addr2.Value) & IIF(LEN(Trim(Fields!IPA_Addr2.Value)) = 0, vbCrlf , Nothing) & Trim(Fields!IPA_City.Value) & ", " & Trim(Fields!IPA_State.Value) & " " & Trim(Fields!IPA_Zip.Value)
Upvotes: 0
Reputation: 14108
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.
Upvotes: 3