Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Convert Clipboard contents to a continuous string

Aug
2,799
144
If the Windows clipboard contains x number of lines of text,
Clip2String.ps1 will convert the lines of text on the clipboard to a continuous string

Code:
R:\>echo Line1^nLine2^nLine3 > clip:

R:\>type clip:
Line1
Line2
Line3

R:\>pshell r:\Clip2String.ps1
Line1 Line2 Line3

R:\>echo %@pshell[r:\Clip2String.ps1]
Line1 Line2 Line3

Clip2String.ps1
Code:
$PSPID = Get-Process PowerShell

if ($pid -eq $PSPid.Id)
    {
        $continuous = (Get-Clipboard -Raw) -replace "\r?\n", " "
    }
    else
    {
        $env:GetClipboard=[TakeCommand.PowerShellHost]::InvokeCommand('type clip:')
        $continuous = $env:GetClipboard -replace '\r?\n', ' '
    }

$continuous

Note that Clip2String.ps1 can be run using PShell in TCC,
or from PowerShell 5.1

Joe
 
Back
Top