如何将richtextbox输出转换为bytearray? [英] How to convert richtextbox output into bytearray?
本文介绍了如何将richtextbox输出转换为bytearray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hai朋友,
我有一个richtextbox,我必须转换那个输出,即使用c#code将一些文本转换为字节数组。我可以这样做...
请帮帮我...
Hai friends,
Am having a richtextbox,and i have to convert that output,ie,some text into byte array using c# code..how can i do this...
please help me...
推荐答案
RichtextBox [ ^ ]有一个Rtf
属性,包含文本和格式指令。它是一个字符串属性。
您可以通过这种方式将其转换为字节数组:
The RichtextBox[^] has aRtf
property holding text and format directives. It is a string property.
You could convert it to byte array this way:
string rtf = myRichtextBox.Rtf;
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(rtf);
这里我使用了UTF8编码,但这个选择取决于你。
希望这会有所帮助。
编辑:稍后,如果你想从字节数组中恢复原始字符串,可以这样做:
Here I used UTF8 encoding, but that choice is up to you.
Hope this helps.
Later, if you want to recover original string from byte array, it can be done this way:
string originalRtf = System.Text.Encoding.UTF8.GetString(bytes);
您必须在两个操作中使用相同的编码。
You have to use the same Encoding in both operations.
这篇关于如何将richtextbox输出转换为bytearray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文