限制剪贴板中的文本数据大小? [英] Limit on text data size in clipboard?

查看:153
本文介绍了限制剪贴板中的文本数据大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**附录:经过数小时的认真研究,我发现自己在吠错树。问题不在于剪贴板本身,而是如果您喂给它格式错误的unicode文本,该怎么办?我的编辑器在处理它时没有问题,但是当剪贴板得到它时,它在文本错误的位置被截断了。
稍后在应用程序中处理字符串时,读取损坏的文件内容将具有相同的效果,因此我现在使用Encoder / DecoderExceptionFallback()功能来检测错误。
令人大开眼界。 **

** 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. **

我的winforms C#应用程序中的剪贴板有问题。我试图将很长的文本(> 140万个字符)保存到剪贴板,并且在使用DataFormats.UnicodeText时我无法取回相同数量的文本。在特定情况下,我复制了1469785个字符,但只返回了502228个字符。如果我将数据标记为DataFormats.WaveAudio,然后在调用Clipboard.GetData()时强制将其强制转换为字符串,则实际上返回的字符数正确。

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.

这不起作用:

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)。

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?

推荐答案

没有限制,至少在使用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.

这篇关于限制剪贴板中的文本数据大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆