C# UWP中两个rtf的合并
我有两个字符串(RTF),我必须以某种方式合并-在两个字符串之间插入新行-以显示在UWP中的RichEditBox中。我读过一个变通方法,其中通过使用两个RichTextBox控件来合并这两个控件,但在UWP中,这并不是一个真正的选项(我也不能在两个RichEditBox控件中显示两个RTF)。有没有其他方法,不使用第三方库?在使用时,我们可以利用 和。以下是一个简单的示例:C# UWP中两个rtf的合并,c#,uwp,rtf,C#,Uwp,Rtf,我有两个字符串(RTF),我必须以某种方式合并-在两个字符串之间插入新行-以显示在UWP中的RichEditBox中。我读过一个变通方法,其中通过使用两个RichTextBox控件来合并这两个控件,但在UWP中,这并不是一个真正的选项(我也不能在两个RichEditBox控件中显示两个RTF)。有没有其他方法,不使用第三方库?在使用时,我们可以利用 和。以下是一个简单的示例: var rtf1 = @"{\rtf1{\fonttbl{\f0 Verdana;}{\f1 Arial;}{\f2 V
var rtf1 = @"{\rtf1{\fonttbl{\f0 Verdana;}{\f1 Arial;}{\f2 Verdana;}{\f3 Calibri;}}{\colortbl;\red255\green255\blue255;\red255\green0\blue0;}\f0\cf2 This is red text marked by Verdana font.\par}";
// Sets rtf1 as the content of the document
editor.Document.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, rtf1);
// Get a new text range for the active story of the document.
var range = editor.Document.GetRange(0, rtf1.Length);
// Collapses the text range into a degenerate point at the end of the range for inserting.
range.Collapse(false);
var rtf2 = @"{\rtf1{\fonttbl{\f0 Times New Roman;}}{\colortbl;\red255\green255\blue255;\red0\green0\blue255;}\f0\cf2 This is blue text marked by Times New Roman font.\par}";
// Inserts rtf2
range.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, rtf2);
//var newrtf = string.Empty;
//editor.Document.GetText(Windows.UI.Text.TextGetOptions.FormatRtf, out newrtf);
//System.Diagnostics.Debug.WriteLine(newrtf);
这将把rtf2合并到rtf1的末尾,并自动创建一个新的有效RTF。您可以使用检索新的RTF。使用时,我们可以利用
和。以下是一个简单的示例:
var rtf1 = @"{\rtf1{\fonttbl{\f0 Verdana;}{\f1 Arial;}{\f2 Verdana;}{\f3 Calibri;}}{\colortbl;\red255\green255\blue255;\red255\green0\blue0;}\f0\cf2 This is red text marked by Verdana font.\par}";
// Sets rtf1 as the content of the document
editor.Document.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, rtf1);
// Get a new text range for the active story of the document.
var range = editor.Document.GetRange(0, rtf1.Length);
// Collapses the text range into a degenerate point at the end of the range for inserting.
range.Collapse(false);
var rtf2 = @"{\rtf1{\fonttbl{\f0 Times New Roman;}}{\colortbl;\red255\green255\blue255;\red0\green0\blue255;}\f0\cf2 This is blue text marked by Times New Roman font.\par}";
// Inserts rtf2
range.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, rtf2);
//var newrtf = string.Empty;
//editor.Document.GetText(Windows.UI.Text.TextGetOptions.FormatRtf, out newrtf);
//System.Diagnostics.Debug.WriteLine(newrtf);
这将把rtf2合并到rtf1的末尾,并自动创建一个新的有效RTF。您可以使用检索新的RTF