开发者

Dumb RichTextBox question

开发者 https://www.devze.com 2022-12-25 20:50 出处:网络
I need to get a list of tags in a text, make their contents bold, and remove them. Can\'t figure out how to make it.

I need to get a list of tags in a text, make their contents bold, and remove them. Can't figure out how to make it.

E.g. wit开发者_如何学Ch the following input:

foo [b]bar[/b]

The result should be:

foo bar

I use the following code to extract the tags:

 Dim matches = Regex.Matches(OriginalRich.Text, String.Format("(\[{0}\])(.*?)(\[/{0}\])", tag), RegexOptions.IgnoreCase Or RegexOptions.Compiled)

Any help would be appreciated.


You could try doing it in two steps: apply the formatting to the whole match including the tags, then make another pass to remove the tags. But if you're doing all this in the same control, I'd say that's your real problem.

I would use a plain TextBox for the input, with a non-editable RichTextBox to preview the result. Basically, the same approach that's used here at StackOverflow (but with a different toolset).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号