[英]Making RegEx Match Bold - VB.NET
This is my current RegEx: \\[b\\](.*?)\\[/b\\]
这是我当前的RegEx: \\[b\\](.*?)\\[/b\\]
That works perfectly fine, it replaces exactly what I want it to. 那工作得很好,它完全替代了我想要的东西。 But, I'm trying to figure out how to make it replace the string between [b][/b]
with a bold string, but the actual text stays the same. 但是,我试图找出如何使它用粗体字符串替换[b][/b]
的字符串,但实际文本保持不变。
Example string: [b]This is an example![/b]
示例字符串: [b]This is an example![/b]
Desired output: This is an example! 所需的输出: 这是一个例子!
I'm using VB.NET and this is what I currently have: 我正在使用VB.NET,这是我目前拥有的:
Dim reg As New Regex("\[b\](.*?)\[/b\]")
Dim str As String = String.Empty
For Each m As Match In reg.Matches(MainBox.Text)
str = reg.Replace(MainBox.Text, "test")
Next
Preview.Show()
Preview.RichTextBox1.Text = str
Preview.Size = New Size(Preview.MaximumSize.Width, Preview.MaximumSize.Height)
You need to set the start of the selection, and set the attributes of the text before inserting it. 您需要设置选择的开始,并在插入之前设置文本的属性。
Preview.RichTextBox1.SelectionStart = Preview.RichTextBox1.Text.Length
Preview.RichTextBox1.SelectionFont = New Font("Tahoma", 12, FontStyle.Bold)
Preview.RichTextBox1.SelectedText = str
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.