1

There are few answers that show different multiline tricks like this one, but nothing explains how to achieve this code format, if ever possible

set-content $file $fll.Replace("Long line 1", "Very Long line 1")
                      .Replace("Long line 2", "Very Long line 2")
                      .Replace("Long line 3", "Very Long line 3")
                      .Replace("Long line 4", "Very Long line 4")
                      .Replace("Long line 5", "Very Long line 5")

If the Replace above are chained in a single line - it works

T.S.
  • 18,195
  • 11
  • 58
  • 78

1 Answers1

3

For your specific code snippet posted, not just the generic case of breaking a chained .NET call across lines:

[1] Put the dot . after the closing parentheses. (generic case of breaking any .NET call across lines)

[2] Enclose the second parameter to Set-Content in parentheses.

Set-Content $file (
    $fll.Replace("Long line 1", "Very Long line 1").
        Replace("Long line 2", "Very Long line 2").
        Replace("Long line 3", "Very Long line 3").
        Replace("Long line 4", "Very Long line 4").
        Replace("Long line 5", "Very Long line 5")
)
kuujinbo
  • 9,272
  • 3
  • 44
  • 57
  • does not work for me - `A positional parameter cannot be found that accepts argument`. And even when I added `-Value`, still - no luck – T.S. Jan 09 '20 at 23:40
  • @T.S.- This is working for me. What is the output of `($PSVersionTable.PSVersion).ToString()` – lit Jan 09 '20 at 23:49
  • @T.S. - thought you just wanted to know how to break _any_ chained .NET call. Updated the answer to be more specific to the exact question. – kuujinbo Jan 09 '20 at 23:49
  • Now, this ^^ works! Thanks. Simple enough but just couldn't find this syntax. Will have to live with the '.' at the end – T.S. Jan 10 '20 at 00:37