真实作者姓名是:PolarBear。
我的功能 searched PolarBear
,结果PolarBear
如我所愿突出显示。
我搜索了Polarbear
,polarbear
并且确实出现在结果中poLarbear
,PolarBear
但没有如我所愿突出显示。
如何像搜索一样使突出显示不区分大小写?谢谢你。
高亮代码:
private void searchComByAuthor()
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(sourceDirXML);
foreach (string fileName in fileEntries)
{
XmlDocument xmlDoc = new XmlDocument(); //* create an xml document object.
string docPath = fileName;
xmlDoc.Load(docPath); //* load the XML document from the specified file.
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("item");
foreach (XmlNode node in nodeList)
{
XmlElement itemElement = (XmlElement)node;
string itemAuthor = itemElement.GetElementsByTagName("author")[0].InnerText;
if (itemAuthor.ToLower() == txtComAuthor.Text.ToString().ToLower())
{
string itemTitle = itemElement.GetElementsByTagName("title")[0].InnerText;
string itemDate = itemElement.GetElementsByTagName("pubDate")[0].InnerText;
string itemDescription = itemElement.GetElementsByTagName("description")[0].InnerText;
string itemXMLFile = Path.GetFileNameWithoutExtension(fileName);
richComByTemplate.AppendText("SYMBOL: " + itemXMLFile + "\nAUTHOR: " + itemAuthor + "\nDATE: " + itemDate +
"\nTITLE: " + itemTitle + "\nDESCRIPTION: " + itemDescription + "\n\n--------\n\n");
}
}
}
int pointer = 0;
int index = 0;
string keyword = txtComAuthor.Text;
string shadow = richComByTemplate.Text;
while (true)
{
//Searching in the copy/shadow
index = shadow.IndexOf(keyword, pointer);
//if keyword not found then the loop will break
if ((index == -1) || (String.IsNullOrEmpty(keyword)))
{
break;
}
richComByTemplate.Select(index, keyword.Length);
richComByTemplate.SelectionColor = Color.Red;
richComByTemplate.SelectionFont = new System.Drawing.Font(richComByTemplate.Font, FontStyle.Bold);
pointer = index + keyword.Length;
}