C# 代码中的富文本格式错误
希望你能帮助
我有以下代码
List<string> comconfig = populate.resolveconfig(_varibledic, populate.GetVaribles[0].Substring(populate.GetVaribles[0].IndexOf("=") + 1)); //get the aray of strings
string config = ""; //create a empty otput string
config = @"\rtf1\ansi\deff0\deftab240 {\fonttbl {\f000 Monaco;} {\f001 Monaco;} } {\colortbl \red255\green255\blue255; \red000\green000\blue000; \red255\green255\blue255; \red000\green000\blue000; }";
config = config + @"\f96\fs20\cb3\cf2 \highlight1\cf0 "; // assigned rtf header to output string
foreach (var strings in comconfig) //loop though array adding to output string
{
config = config + strings + @"\par ";
}
config = config + "}"; //close of RTF code
因此尝试创建一个稍后可以显示的 RTF 字符串。 comconfig 是一个字符串数组,带有一些用于突出显示和其他内容的 RTF 标记。
问题是,如果我使用@,那么我会得到双\,这会弄乱RTF,如果我不使用它们,那么转义字符会弄乱代码?
通过添加预格式化的 RTF 标头和中间的字符串数组来构建此字符串的最佳方法是什么?它最终显示在 RTF.textbox 中。或根据用户请求转换为纯文本字符串。我需要忽略转义字符而不弄乱 RTF?
干杯
亚伦
hoping you can help
I have the following code
List<string> comconfig = populate.resolveconfig(_varibledic, populate.GetVaribles[0].Substring(populate.GetVaribles[0].IndexOf("=") + 1)); //get the aray of strings
string config = ""; //create a empty otput string
config = @"\rtf1\ansi\deff0\deftab240 {\fonttbl {\f000 Monaco;} {\f001 Monaco;} } {\colortbl \red255\green255\blue255; \red000\green000\blue000; \red255\green255\blue255; \red000\green000\blue000; }";
config = config + @"\f96\fs20\cb3\cf2 \highlight1\cf0 "; // assigned rtf header to output string
foreach (var strings in comconfig) //loop though array adding to output string
{
config = config + strings + @"\par ";
}
config = config + "}"; //close of RTF code
So trying to create a RTF string that I can later display. comconfig is an array of strings with some RTF mark up for highlighting and stuff.
trouble is that if I use @ then I get double \ which mess up the RTF, and if i dont use them, then the escape charatures mess up the code??
what is the best way to build up this string by adding a preformated RTF header and the aray of strings in the middle. it is displayed finaly in a RTF.textbox. or converted to a plain text string at the users request. I need to ignore the escape charatures with out messing up the RTF?
Cheers
Aaron
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,您不会得到双
\
。您对字符串的调试器显示感到困惑。它显示了如果您用 C# 编写的字符串(不带 @),该字符串会是什么样子。单击最右侧的望远镜图标,然后选择文本可视化工具。No, you don't get a double
\
. You're getting confuzzled by the debugger display of the string. It shows you what the string looks like if you had written it in C# without the @. Click the spy glass icon at the far right and select the Text Visualizer.