<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 如何:將 RTF 轉換為純文本(C# 編程指南) RTF 格式是 Microsoft 于 20 世紀 80 年代后期開發的一種文件格式,旨在實現不同操作系統之間的文檔交換。Microsoft Word 和 WordPad 都可以讀寫 RTF 文件。在 .NET Framework 中,可以使用 [RichTextBox](https://msdn.microsoft.com/zh-cn/library/system.windows.forms.richtextbox.aspx) 控件創建支持 RTF 且支持用戶以 WYSIWIG 方式將格式應用于文本的字處理器。 也可以使用 [RichTextBox](https://msdn.microsoft.com/zh-cn/library/system.windows.forms.richtextbox.aspx) 以編程方式將 RTF 格式代碼從文檔中移除,從而將該文檔轉換為純文本。執行這種類型的操作無需在 Windows 窗體中嵌入該控件。 ## 在項目中使用 RichTextBox 控件 1. 添加對 System.Windows.Forms.dll 的引用。 2. 為 **System.Windows.Forms** 命名空間添加 using 指令(可選)。 下面的示例將示例 RTF 文件轉換為純文本。文件包含 RTF 格式設置 (如字體信息),四個 Unicode 字符和四個擴展的 ASCII 字符。代碼示例打開文件,將其內容設置為 [RichTextBox](https://msdn.microsoft.com/zh-cn/library/system.windows.forms.richtextbox.aspx),當 RTF,檢索該內容作為文本,并在 [MessageBox](https://msdn.microsoft.com/zh-cn/library/system.windows.forms.messagebox.aspx)的文本和輸出該文本到一個 UTF-8 格式的文件。 **MessageBox** 和輸出文件包含以下文本: ``` The Greek word for "psyche" is spelled ψυχ?. The Greek letters are encoded in Unicode. These characters are from the extended ASCII character set (Windows code page 1252): a??? ``` ``` // Use NotePad to save the following RTF code to a text file in the same folder as // your .exe file for this project. Name the file test.rtf. /* {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;} {\f1\fnil\fprq1\fcharset0 Courier New;}{\f2\fswiss\fprq2\fcharset0 Arial;}} {\colortbl ;\red0\green128\blue0;\red0\green0\blue0;} {\*\generator Msftedit 5.41.21.2508;} \viewkind4\uc1\pard\f0\fs20 The \i Greek \i0 word for "psyche" is spelled \cf1\f1\u968?\u965?\u967?\u942?\cf2\f2 . The Greek letters are encoded in Unicode.\par These characters are from the extended \b ASCII \b0 character set (Windows code page 1252): \'e2\'e4\u1233?\'e5\cf0\par } */ class ConvertFromRTF { static void Main() { // If your RTF file isn't in the same folder as the .exe file for the project, // specify the path to the file in the following assignment statement. string path = @"test.rtf"; //Create the RichTextBox. (Requires a reference to System.Windows.Forms.) System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox(); // Get the contents of the RTF file. When the contents of the file are // stored in the string (rtfText), the contents are encoded as UTF-16\. string rtfText = System.IO.File.ReadAllText(path); // Display the RTF text. This should look like the contents of your file. System.Windows.Forms.MessageBox.Show(rtfText); // Use the RichTextBox to convert the RTF code to plain text. rtBox.Rtf = rtfText; string plainText = rtBox.Text; // Display the plain text in a MessageBox because the console can't // display the Greek letters. You should see the following result: // The Greek word for "psyche" is spelled ψυχ?. The Greek letters are // encoded in Unicode. // These characters are from the extended ASCII character set (Windows // code page 1252): a??? System.Windows.Forms.MessageBox.Show(plainText); // Output the plain text to a file, encoded as UTF-8\. System.IO.File.WriteAllText(@"output.txt", plainText); } } ``` RTF 字符以八位編碼。但是,除了從指定的代碼頁,擴展 ASCII 字符之外用戶可以指定 Unicode 字符。由于 [RichTextBox.Text](https://msdn.microsoft.com/zh-cn/library/system.windows.forms.richtextbox.text.aspx) 屬性為 [string](https://msdn.microsoft.com/zh-cn/library/362314fe.aspx) 類型,因此字符按 Unicode UTF-16 進行編碼。源 RTF 文檔中的所有擴展的 ASCII 字符和 Unicode 字符都在文本輸出中進行了正確的編碼。 如果使用 [File.WriteAllText](https://msdn.microsoft.com/zh-cn/library/system.io.file.writealltext.aspx) 方法將文本寫入磁盤,則文本將按 UTF-8(沒有字節順序標記)進行編碼。 ## 請參閱 [System.Windows.Forms.RichTextBox](https://msdn.microsoft.com/zh-cn/library/system.windows.forms.richtextbox.aspx) [字符串(C# 編程指南)](https://msdn.microsoft.com/zh-cn/library/ms228362.aspx)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看