Skip to content

Out-String should not append a trailing newline #14444

@mklement0

Description

@mklement0

Summary of the new feature/enhancement

It should be possible to use Out-String in a manner that doesn't append a trailing newline, which is what it currently does and has always done.

Note that -NoNewLine is not a solution, because it suppresses all newlines, so that two or more output lines are then simply directly concatenated (like -join ''; e.g. 1, 2 | Out-String -NoNewLine yields 12).

Here's a demonstration of the problem:

# CURRENT behavior:
PS> ('foo' | Out-String) -replace '\r?\n', '<newline>'
foo<newline>   #  A newline was appended.

I see two options:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-By DesignThe reported behavior is by design.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions