问题1:要从一个字符串中查找出符合条件的子字符串,在输出字符串中将查找到的子字符串的颜色变为红色,请各位高手给予指点,这个问题已经卡了很长时间了。谢谢。
代码如下:
string str = "abcdabcd";
string str1 = "abc";
if (str.Contains(str1))
{
if (str.IndexOf(str1) > 0)
{
//不会写了,请给予指点,没有具体代码,给个思路也行
}
}
代码如下:
string str = "abcdabcd";
string str1 = "abc";
if (str.Contains(str1))
{
if (str.IndexOf(str1) > 0)
{
//不会写了,请给予指点,没有具体代码,给个思路也行
}
}
解决方案 »
- 程序开机启动后读不到ini文件
- 给面试官看的自己的项目介绍应该怎么写,比较好,有没有例子或模板可以参考
- 我用程序创建一个xml文件,出现一点问题
- 请问如何在windows编程中(不是web应用程序)通过触发一个事件弹出另一个窗体,但是主窗体并不消失。
- C# data reader 的使用
- 怎样判断二个DataRow对象的父表的结构是否相等?
- 初学C# 有没有类似java的API文档查询各组件的方法
- 一个初学者的问题,请问大虾!
- 开发C#程序的环境用以下组成有什么问题吗
- 请问各位大侠 VS2012 c#开发的wpf工程如何打包安装?
- winform中的dataGridView标题文字颜色如何改变
- 一个关于 类中字段值的问题
string str = "abcdabcd";
string str1 = "abc";
if (str.Contains(str1))
{
if (str.IndexOf(str1) > 0)
{
str = str.Replace(str1, "<span style=\"color: #FF0000\">" + str1 + "<span>");
Response.Write(str);
}
}
string str=@"";
if (richTextBox1.Find(str)>0)
{
int pos=richTextBox1.Find(str);
richTextBox1.SelectionStart=pos;
richTextBox1.SelectionLength=str.Length;
richTextBox1.SelectionFont=fnt;
richTextBox1.SelectionColor=Color.Read;
}
Replace(str, "<span style=\"color: #FF0000\">" + str + "<span>");
if (this.richTextBox1.SelectedText.Length > 0)
{
this.richTextBox1.SelectionColor = Color.Red; }
感谢7楼给予的帮助,我尝试了一下,确实可以改变在richTextBox中查找到的子字符串的颜色了,但由于我没有把问题表述清楚,所以到现在我的问题依然没有解决,因为我的RichTextBox的内容有很多,并且还有换行,如下图所示:但上面代码中的RichTextBox的find方法只能查找一次,对于后面的就无能为力了,我也查看了RichTextBox类的其他方法的说明,都没有找到合适的,在此还恳请高手们给予进一步的指点,万分感谢!!
When he grew up, he took the tests for officials,
2. 廷中吏无所不狎侮。
There was none of the officials in the great hall whom he did not dare to treat cavalierly.
3. 沛中豪杰吏闻令有重客,皆往贺。
When the eminent and distinguished persons and officials of P'ei heard that the magistrate had an important guest, they all went to congratulate him.
4. 萧何为主吏,主进,
Hsiao Ho was the superintendent of officials and took charge of the offerings.
5. 高祖为亭长,素易诸吏,
Although Kao-tsu was [only] Chief of a t'ing, he used to treat his fellow-officials contemptuously,
string str=@"";
int iIndex = richTextBox1.Find(str);
While iIndex >0
{richTextBox1.SelectionStart=pos;
richTextBox1.SelectionLength=str.Length;
richTextBox1.SelectionFont=fnt;
richTextBox1.SelectionColor=Color.Read;
iIndex = richTextBox1.Find(str,iIndex,RichTextBoxFinds.WholeWord);加这个
}
if (richTextBox1.Find(str)>0)
{
int pos=richTextBox1.Find(str);
richTextBox1.SelectionStart=pos;
richTextBox1.SelectionLength=str.Length;
richTextBox1.SelectionFont=fnt;
richTextBox1.SelectionColor=Color.Read;
}
Replace(str, "<span style=\"color: #FF0000\">" + str + "<span>");
while (iIndex > 0)
{
this.richTextBox1.SelectionStart = iIndex;
this.richTextBox1.SelectionLength = this.textBox1.Text.Length;
//this.richTextBox1.SelectedText = this.textBox1.Text;
this.richTextBox1.SelectionColor = Color.Red;
iIndex = this.richTextBox1.Find(this.textBox1.Text,iIndex + this.textBox1.Text.Length,RichTextBoxFinds.WholeWord);
}测试过的