gpt4 book ai didi

c# - 从那里获取数据然后返回到 Windows 剪贴板

转载 作者:太空狗 更新时间:2023-10-29 23:08:55 26 4
gpt4 key购买 nike

我想获取当前存储在 Windows 剪贴板中的数据并将其保存在一个变量中,然后将数据放回剪贴板。

现在我正在使用这段代码:

object l_oClipBrdData = Clipboard.GetDataObject();
Clipboard.SetDataObject(l_oClipBrdData ,true);

但在这样做之后剪贴板是空的。

我做错了什么?

最佳答案

这是一个演示“剪贴板”对象的示例:

string text;
string[] a;

if (Clipboard.ContainsText())
{
text = Clipboard.GetText(TextDataFormat.Text);

// the following could have been done simpler with
// a Regex, but the regular expression would be not
// exactly simple

if (text.Length > 1)
{
// unify all line breaks to \r
text = text.Replace("\r\n", "\r").Replace("\n", "\r");

// create an array of lines
a = text.Split('\r');

// join all trimmed lines with a space as separator
text = "";

// can't use string.Join() with a Trim() of all fragments
foreach (string t in a)
{
if (text.Length > 0)
text += " ";
text += t.Trim();
}

Clipboard.SetDataObject(text, true);
}
}

关于c# - 从那里获取数据然后返回到 Windows 剪贴板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14635599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com