我的问题有两个部分:
1)如何Dell Canada在字符串中搜索句子(例如,)I am working in Dell Canada,我发现它......).
2)第二部分是我的字符串是RichTextBox中的文本,所以我想找到所选句子的TextRange并应用某些装饰.
谢谢.
给它一个旋转,它将它设置为粗体.您可以使用RichTextBox上的许多Selection ...属性,还要注意它是一个不区分大小写的搜索:
string textToSearchFor = "Dell Canada";
int index = richTextBox1.Text.IndexOf(textToSearchFor, StringComparison.OrdinalIgnoreCase);
if (index >= 0)
{
richTextBox1.Select(index, textToSearchFor.Length);
richTextBox1.SelectionFont = new Font("Arial", 12f, FontStyle.Bold);
}
else
{
// not found
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5539 次 |
| 最近记录: |