在 RichTextBox 中格式化 rtf/unicode/utf-8 的最简单方法?
我目前正在把头撞在墙上试图解决这个问题。 但长话短说,我想将 2 个 UTF-8 '\u0002' 之间的字符串转换为粗体格式。 这是针对我正在开发的 IRC 客户端的,所以我经常遇到这些问题。 我有 treid 正则表达式,发现 rtf 上的匹配为 ((\'02) 可以捕获它,但我不确定如何匹配最后一个字符并将其更改为 \bclear 或任何 rtf 格式化关闭。
我无法准确粘贴我试图解析的文本,因为字符被从帖子中过滤掉了,但是当查看 char 值时,它的整数为 2。
以下是粘贴有问题的文本的尝试:
[02:34]测试测试
I'm currently beating my head against a wall trying to figure this out. But long story short, I'd like to convert a string between 2 UTF-8 '\u0002' to bold formating. This is for an IRC client that I'm working on so I've been running into these quite a bit. I've treid regex and found that matching on the rtf as ((\'02) works to catch it, but I'm not sure how to match the last character and change it to \bclear or whatever the rtf formating close is.
I can't exactly paste the text I'm trying to parse because the characters get filtered out of the post. But when looking at the char value its an int of 2.
Here's an attempt to paste the offending text:
[02:34] test test
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 或
,
具体取决于您是否想将 \u0002 保留在那里。
\b 和 \b0 在 RTF 中打开和关闭粗体。
You could use either
or
depending on whether you want to keep the \u0002s in there.
The \b and \b0 turn the bold on and off in RTF.
我没有测试用例,但您也可以使用
Clipboard
类的GetText
方法 与Unicode
TextDataFormat。 基本上,我认为您可以将输入放入剪贴板并以不同的格式取出(适用于 RTF 等)。 下面是 MS 的演示代码(不直接适用,但演示了 API):当然,如果你这样做,你可能想要保存和恢复剪贴板中的内容,否则你可能会让你的用户不高兴!
I don't have a test case, but you could also probably use the
Clipboard
class'sGetText
method with theUnicode
TextDataFormat. Basically, I think you could place the input in the clipboard and get it out in a different format (works for RTF and the like). Here's MS's demo code (not applicable directly, but demonstrates the API):Of course, if you do that, you probably want to save and restore what was in the clipboard, or else you may upset your users!