[英]How to Read and modify Hindi .rtf file programmatically?
I have a hindi RTF file with content like: 我有一个印地文RTF文件,内容如下:
कोलकाता, 11 दिसंबर पश्चिम बंगाल के बर्दवान जिले में कक्षा नौ की एक छात्रा ने फांसी लगाकर आत्महत्या कर ली।
的最高评分,11月份的最高排名最高排名最高排名最高排名最高排名
In my console application I want to read that RTF file and Change some content programatically. 在我的控制台应用程序中,我想读取该RTF文件并以编程方式更改一些内容。
I using streamreader to read the file but when converting to string it is producing the following output: 我使用streamreader读取文件,但是在转换为字符串时会产生以下输出:
ÚUæCþUèØ-SßæS‰Ø
ÚUæCþUèØ-SßæS‰Ø
×Âý Ñ Sßæ§Ù Üê •¤è ¼ßæ ÂØæü# ×æ˜æ ×ð´ ãUôÙð •¤æ ¼æßæ
×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
ÖæðÂæÜ, vv ç¼â¢ÕÚ (¥æ§ü°°Ù°â)Ð ×ŠØ Âý¼ðàæ ×ð´ Sßæ§Ù Üê ¥æñÚ ÇðU¢»ê âð ¥Õ Ì•¤ •¤§ü Üæð»æð´ •¤è ×æñÌ ãUæð ¿é•¤è ãñU ¥õÚU ¥SÂÌæÜ ×ð´ ç¿ç•¤ˆâ•¤èØ âéçßÏæ¥ô´ •¤è •¤×è •ð¤ âæÍ-âæÍ ¼ßæ¥ô´ •ð¤ ¥Öæß •ð¤ Öè ¥æÚUæð ܻÌð ÚãðU ãñU¢Ð
ÖæðÂæÜ,vvç¼¢ÕÚ(¥æ§ü°°Ù°â)Ð׊ØÂý¼ðàæ×ð´Sßæ§ÙÜê¥æñÚÇðU¢»êâð¥¥Õ•¤•¤§§üÜæð»æ𴕤 è×æñÌãUæð¿é•¤èãñU¥õÚU¥SÂÌæÜ×ð´ç¿ç•¤ˆâ•¤èØâéçßÏæ¥ô••è•¤×è•ð¤âæÍ-âæͼßæ¥ô••ð¤ ¥Öæß•ð¤Öè¥æÚUæðÂÜ»ÌðÚãðUãñU¢Ð
SßæS‰Ø çßÖæ» Ùð ãUæÜæ¢ç•¤ ØãU ¼æßæ 畤Øæ ãñU 畤 Úæ…Ø ×ð´ ×æñâ×è ÚUæð», Sßæ§Ù Üê •ð¤ ©Â¿æÚ •ð¤ çÜ° Âý¼ðàæ •ð¤ ¥SÂÌæÜæð´ ×ð´ ¥æßàØ•¤ ¼ßæ¥æð´ •¤æ ÂØæü# ÂýÕ¢Ï ç•¤Øæ »Øæ ãñUÐ
SßæS‰ØçßÖæ»ÙðãUæÜæ¢ç•¤ØãU¼æßæ畤ØæãñU畤Øæ…Ø×ðð××æñâ×èÚUæð»,Sßæ§ÙÜê•ð¤©Â¿ •¥¥SÂÌæÜæð´×ð¥¥æßàØ•¤¼ßæ¥æ𴕤æØØü#ÃýÕ¢Ï畤Øæ»ØæãñUÐ
I have tried the windows form RichTextBox to read the RTF file, but it always show Invalid File Format. 我已经尝试过Windows窗体RichTextBox来读取RTF文件,但它始终显示无效的文件格式。
So what will be the best possible solution to read and modify rtf file in C# 那么,在C#中读取和修改rtf文件的最佳解决方案是什么?
StreamReader sr = new StreamReader(fpath, Encoding.Default, true);
string s1 = sr.ReadToEnd();
sr.Close();
also tried 也尝试过
using (System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox())
{
// Get the contents of the RTF file. Note that when it is
// stored in the string, it is encoded as UTF-16.
string s = System.IO.File.ReadAllText(fpath);
// Convert the RTF to plain text.
rtBox.Rtf = s; // error file format invalid
string plainText = rtBox.Text;
}
The RichTextBox
control can load an RTF file directly , do not use StreamReader
to read RTF file because it can contain a lot of Control Characters
. RichTextBox
控件可以直接加载RTF文件 ,请勿使用StreamReader
读取RTF文件,因为它可能包含很多Control Characters
。
After loading the file to the RichTextBox
, use the Text
property to get the plain text of the file. 将文件加载到
RichTextBox
,使用Text
属性获取文件的纯文本。
RichTextBox
also has a SaveFile
method to save the modified content to a file. RichTextBox
还具有SaveFile
方法,可将修改后的内容保存到文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.