sebastian-c
sebastian-c

Reputation: 15395

Placing a string on the clipboard without a newline

I have a custom function which converts a path with backslashes on the clipboard to one with forward slashes and pastes it back onto the clipboard. The trouble is, when it is pasted back, it comes with a newline. I can't seem to find where this newline has come from as it doesn't seem to be a newline character as such:

btf <- function(){
  backstring <- readClipboard()
  forstring <- gsub("\\\\", "/", backstring)
  writeClipboard(forstring)
}

So to use a sample path: C:\path\to\folder
1. copy path
2. run btf() in R
3. paste

The pasted copy now has a newline after it. I'm running R 3.0.1 under Windows 7.
How can I prevent this newline from appearing?

Upvotes: 6

Views: 1399

Answers (1)

user1609452
user1609452

Reputation: 4444

USE:

btf <- function(){
  backstring <- readClipboard()
  forstring <- gsub("\\\\", "/", backstring)
  writeClipboard(charToRaw(paste0(forstring, ' ')))
}

Upvotes: 4

Related Questions