Here is my simple approach. You say it’s not practical, but it works for me. Thanks for introducing the function clipboard to me.
function cbtomatrix(clipboard::AbstractString)
rowsep = "\r\n"
# add +1 if there is no row separator at the end (see example)
nrows = length(findall(rowsep, clipboard)) + 1
data = parse.(Float64, split(clipboard))
return reshape(data, nrows, :)
end
@zweiglimmergneis, brilliant.
With your function it becomes totally convenient NB: we need to add +1 to nrows: nrows = length(findall(rowsep, clipboard)) + 1
This one is nice too and accepts both comma-separated and spaces-separated clipboard data:
function clip2m()
str = split(clipboard(), "\r\n")
str = replace.(str, "," => " ")
nr, nc = length(str), length(split(str[1]))
[parse(Float64,split(str[i])[j]) for i in 1:nr, j in 1:nc]
end
# copy columnar data (comma- or space-separated) to clipboard then run:
julia> clip2m()
4×2 Matrix{Float64}:
675.7 2962.0
636.6 2961.0
565.9 2964.0
517.5 2956.0
If they are different inputs, just use the delim parameter to specify the delimiter. If you have a single input that uses both comma and space separators (or you don’t know whether it is using commas or spaces), no; you’d have to preprocess the input with replace(inputstring, ','=>' ') or similar AFAIK.
Yes, but that can be trivially handled at the source (jEdit, Excel, etc.). The great usefulness of this is to quickly and easily get the data into a Julia matrix for further processing, plotting, etc. In particular when working on 2 machines with a remote desktop connection, where the clipboard communicates across.