Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Multi-line text becomes a one-liner

Reply
 
Old 06-28-2007   #1 (permalink)
MichielV


 
 

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 SpecsSystem Spec
Old 06-28-2007   #2 (permalink)
Kiron


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46