剪贴板中文本数据大小的限制?
** 附录:经过几个小时的认真研究,我发现我找错了对象。问题不在于剪贴板本身,而是如果你向它提供格式错误的 unicode 文本(我显然就是这样做的),会发生什么。我的编辑器处理它没有问题,但是当剪贴板获取它时,它在文本中错误所在的位置被截断。 当稍后在应用程序中处理字符串时,读取“损坏”的文件内容将具有相同的效果,因此我现在使用 Encoder/DecoderExceptionFallback() 功能来检测错误。 真是让人大开眼界。 **
我的 winforms C# 应用程序中的剪贴板有问题。我试图将很长的文本保存到剪贴板(> 140 万个字符),并且在使用 DataFormats.UnicodeText 时我无法取回相同数量的文本。在特定情况下,我复制 1469785 个字符,但只返回 502228 个字符。如果我将数据标记为 DataFormats.WaveAudio,然后在调用 Clipboard.GetData() 时强制转换为字符串,我实际上会得到正确的字符数。仅使用文本时似乎有一些特殊处理。
这不起作用:
Clipboard.SetData( System.Windows.Forms.DataFormats.UnicodeText, _sb.ToString() );
StringBuilder _sb2 = new StringBuilder( Clipboard.GetData( DataFormats.UnicodeText ) );
虽然这样做:
Clipboard.SetData( System.Windows.Forms.DataFormats.WaveAudio, _sb.ToString() );
StringBuilder _sb2 = new StringBuilder( ( string )Clipboard.GetData( DataFormats.WaveAudio ) );
使用 DataFormat.Text 也没有帮助,但添加了 unicode 字符的损坏(出于明显的原因:D)。
我在网上找到的所有信息都说剪贴板大小没有可用内存的限制,那么这如何解释呢?文本数据格式真的有一些特殊处理吗?我确信我在这里遗漏了一些重要的东西,但是什么呢?
** ADDENDUM: After some serious hours of research i found that i was barking up the wrong tree. The problem was not the clipboard itself but what happens if you feed it malformed unicode text which i apparently did. My editor had no problem handling it but when the clipboard got it it was truncated at the point where the error was in the text.
Reading 'damaged' file content will have the same effect when strings are handled in the application later and i therefore now use the Encoder/DecoderExceptionFallback() functionality to detect errors.
Quite an eye opener. **
I have a problem with the Clipboard in my winforms C# application. I'm trying to save a very long text to the clipboard (>1.4 million chars) and when using the DataFormats.UnicodeText i cannot get back the same amount of text. In a specific case i copy 1469785 characters but get back only 502228 chars. If i tag the data as DataFormats.WaveAudio and then force as string cast at the call to Clipboard.GetData() i actually get the correct number of characters back. There seems to be some special handling when using text only.
This doesn't work:
Clipboard.SetData( System.Windows.Forms.DataFormats.UnicodeText, _sb.ToString() );
StringBuilder _sb2 = new StringBuilder( Clipboard.GetData( DataFormats.UnicodeText ) );
While this does:
Clipboard.SetData( System.Windows.Forms.DataFormats.WaveAudio, _sb.ToString() );
StringBuilder _sb2 = new StringBuilder( ( string )Clipboard.GetData( DataFormats.WaveAudio ) );
Using DataFormat.Text didn't help either but added the mangling of the unicode characters (for obvious reasons :D).
All information i can find on the net says there is no limitation on clipboard size short of the available memory so how can this be explained? Is there really some special handling with the text data format? I'm sure i'm missing some cruical thing here but what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至少在使用 Windows API 时没有限制。但是,除非您希望其他应用程序能够粘贴此内容,否则首先使用剪贴板可能没有意义。
There is no limit, at least when using the windows API. However, unless you intend for some other app to be able to paste this, there's probably no point in using the clipboard in the first place.