![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Multi-line text becomes a one-liner Hi, I want to update some lines in a text file. I can 'cat' the file but when I pass the contents of the file to a function the multi-line content suddenly becomes a one-liner. How can I prevent the removal of all newline characters? <code> function update_text ( [string]$MYNFC ) { $MYNFC } # Get contents of a multiline file $NFC = cat c:\temp\test.txt "Original contents of NFC =" $NFC # Update contents of $NFC $NFC = update_text $NFC "Contents of NFC after update_text =" $NFC </code> Output: 31# D:\data\servers\test.ps1 Original contents of NFC = line 1 line 2 line 3 line 4 Contents of NFC after update_text = line 1 line 2 line 3 line 4 regards Michiel |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Multi-line text becomes a one-liner The reason is that the $MYFUNC parameter is strong type as a [string] You could strong type it as a string array [string[]] function update_text ( [string[]]$MYNFC ) { $MYNFC } ....or let PowerShell handle it for you: function update_text ( $MYNFC ) { $MYNFC } -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| script for multi text replacement | VB Script | |||
| Multi-line Character Detection | .NET General | |||
| WaitForExit() times out when I try to capture multi-line Stdout | .NET General | |||
| Display multi line status with WriteProgress | PowerShell | |||
| Multi-line aka block comments in Powershell | PowerShell | |||