
true if this encoder can flush its
state at the end of the conversion;
otherwise,false. To ensure correct
termination of a sequence of blocks of
encoded bytes,the last call to
GetBytes can specify a value of true
for flush.
但是我不明白同花顺是做什么的,也许我喝醉了或者是某事:).请你详细解释一下.
解决方法 假设您通过套接字连接接收数据.您将收到一个长文本作为几个byte []块.1个Unicode字符可能占用UTF-8流中的2个字节,并且它可以分割为2个字节的块.单独编码2个字节块(并连接字符串)会产生错误.
所以你只能在最后一个块上指定flush = true.当然,如果你只有1个街区,那么这也是最后一个.
提示:使用TextReader并让它为您处理此问题.
编辑
镜像问题(实际上是问:GetBytes)稍微难以解释.
使用flush = true与在GetBytes(…)之后使用Encoder.Reset()相同.它清除了编码器的“状态”,
including trailing characters at the end of the prevIoUs data block,such as an unmatched high surrogate
基本思路是相同的:当从字符串转换为字节块时,反之亦然,这些块不是独立的.
总结以上是内存溢出为你收集整理的c# – 为什么我们在Encoder.GetBytes方法中使用flush参数全部内容,希望文章能够帮你解决c# – 为什么我们在Encoder.GetBytes方法中使用flush参数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)