How to trim excess linefeeds from my measures #588
-
I have the following code to format my DAX code and write it into the "Description" field.
This worked fine until 3.30. Now every time I run it I am getting a new blank line inserted at the top, so after running it a few times, I have 8 or 9 blank lines at the top. I think my macro is working against a probable improvement in 3.3 where measures formatted in Desktop will now show the formula starting on a new line, not on the line with the measure name. I tried using string.Trim() but that just gives me an error about strings converting to char. So I guess I am asking for help in 2 ways:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @edhans, foreach (var m in Model.AllMeasures)
{
m.Expression = '\n' + m.Expression.Replace("\r\n", "\n").TrimStart('\n');
} I am not sure I understand your second question. This code seems to work correctly without any conversion errors foreach (var m in Model.AllMeasures)
{
m.Description = string.Join("\n", m.Expression.Split('\n').Take(16));
} |
Beta Was this translation helpful? Give feedback.
Hi @edhans,
you can use
TrimStart
to remove all leading blank lines. In the following example I've also included.Replace("\r\n", "\n")
just to be sure that the line ending characters are normalised in the formatted string.I am not sure I understand your second question. This code seems to work correctly without any conversion errors