Created
December 27, 2016 15:40
-
-
Save bender-the-greatest/2d5bff211684727ffa226937d753cfc8 to your computer and use it in GitHub Desktop.
Powershell function to convert a multiline string to a single line string with line break characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Powershell function to convert a multiline string to a single line string with line break characters | |
# | |
# Example usage: | |
# # Replace line breaks with \r\n (Windows-style line endings) | |
# cat 'nginx.cer' | Convert-MultilineToSingleLine | |
# # Replace line breaks with \n (Unix/Linux-style line endings) | |
# cat 'nginx.cer' | Convert-MultilineToSingleLine -n | |
function Convert-MultilineToSingleLine { | |
Param( | |
[Parameter(ValueFromPipeline=$True,Mandatory=$True)] | |
[string]$multilineString, | |
[switch]$nixEnd = $False | |
) | |
begin { | |
$fullPipeline = "" | |
$linebreak = "\r\n" | |
if ($nixEnd) { | |
$linebreak = "\n" | |
} | |
} | |
process { $fullPipeline += $multilineString + $linebreak } | |
end { $fullPipeline } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment