Answered by:
Read .xaml contents to multi-line string

Question
-
I am attempting to write a function that retrieves the text contents of a .xaml file and saves it as a multiline string, retaining line breaks and basic formatting.
Get-Content returns an array of strings, so I would like to either convert this array into a single multi-line string (one line per index) or find some alternate means of getting the data into a multi-line string.
Thanks in advance!
Thursday, May 17, 2018 3:49 PM
Answers
-
Get-Content filename -Raw
\_(ツ)_/
- Marked as answer by natpalmer1776 Thursday, May 17, 2018 4:01 PM
Thursday, May 17, 2018 3:51 PM
All replies
-
Get-Content filename -Raw
\_(ツ)_/
- Marked as answer by natpalmer1776 Thursday, May 17, 2018 4:01 PM
Thursday, May 17, 2018 3:51 PM -
I found a solution that implemented some .Net
$result = [string]::join([environment]::newline, (Get-Content $filename))
[source] - https://weblogs.asp.net/soever/powershell-pitfalls-reading-text-from-file-using-get-content
However, your solution is a lot cleaner and will be easier for me to understand when I'm reviewing it later.
Thanks a ton!
Thursday, May 17, 2018 4:06 PM -
My solution does not alter the content. Yours does.
By the way. Here is how to do a join in PowerShell.
(Get-Content$filename) -join "`n"
"-Raw" just avoids creating an array in the first place.
\_(ツ)_/
Thursday, May 17, 2018 4:19 PM -
What is `n ?Thursday, May 17, 2018 4:31 PM
-
The current NewLine character.
\_(ツ)_/
Thursday, May 17, 2018 4:45 PM