yardyy
yardyy

Reputation: 89

Howto add a string prefix

I have a simple script that when started, will monitor the clipboard and then paste that into a text file as below, that works fine, but what I would like and cannot figure how to do is to add a bit of text before the clipboard text..

So for eg.

Clipboard that is pasted is image_003_lon I would like to add Dept-342 to the beginning of the line then the pasted text. so should read , Dept-342 image_003_lon

The Dept-342 text is static, this would not change.

function Get-ClipboardText(){
    Add-Type -AssemblyName System.Windows.Forms
    $tb = New-Object System.Windows.Forms.TextBox
    $tb.Multiline = $true
    $tb.Paste()
    $tb.Text

$clipboard = Get-ClipboardText | Out-File -Append $tempfile -encoding ASCII

Upvotes: 0

Views: 250

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

Just use a format string to append the text. Also, you don't have to create a form to access the clipboard since there is a Get-Clipboard cmdlet ;-):

'Dept-342 {0}' -f (Get-Clipboard) | Out-File -Append $tempfile -encoding ASCII

Upvotes: 2

Related Questions