|
Re: Why does get-content on a text file remove crlf when cast to a string? Get-Content returns the contents of the file as a collection of strings (one
string per line). Since you are casting the collection to a string, the
CRLFs are lost. Instead, join can be used as shown below to obtain a single
string.
gci -i Assemblyinfo.cs -r | %{$contents=gc
$_.FullName;doWork([system.string]::join("`r`n", $contents)) }
The above will display the contents on the screen in the same way like the
first snippet.
--
Narayanan Lakshmanan [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"Mark" <mwatts at hotmail dot com> wrote in message
news:4DBDB20F-A444-47F4-AA33-419B4C2B3C99@microsoft.com...
>
> Given the following:
>
> function doWork($fileContent)
> {
> write-output $fileContent
> }
>
> gci . -i AssemblyInfo.cs -r | % { doWork (gc $_.FullName) }
>
> will result in the contents of all AssemblyInfo.cs files being dumped to
> the screen. However, this
>
> function doWork([string]$fileContent)
> {
> write-output $fileContent
> }
>
> gci . -i AssemblyInfo.cs -r | % { doWork (gc $_.FullName) }
>
> results in all crlf'ds being removed.
>
> I am trying to update version information and I have a reg-ex in 'doWork'
> that does the updates but the problem is that whenver the results of
> get-contents is processed as a string, all the crlf information vanishes
> which results in corrupted files?
>
> What am I doing wrong?
>
> thanks
> -mark
>
> --
> -mark |