Note that there are some explanatory texts on larger screens.

plurals
  1. POHighlighting User Defined Keywords in RichTextBox
    primarykey
    data
    text
    <p>I am searching XML files to see if there are contents which match the words inserted in these textboxes <code>txtComKeyword1</code>, <code>txtComKeyword2</code>, <code>txtComKeyword3</code> and/or <code>txtComKeyword4</code>. The function below is working, but may I know how can I highlight the keywords that user entered in the four textboxes that match that appear in my <code>richComResults</code> richtextbox?</p> <p>For example, my user will fill in those four textboxes ie. txtComKeyword1, txtComKeyword2, txtComKeyword3 and txtComKeyword4. Then, my code will parse the XML file to see if the nodes contain these four keywords, if yes, the nodes' data will be output on my richComResults, I wanna highlight those four keywords (eg txtComKeyword1=hello, txtComKeyword2=bye, txtComKeyword3=morning, txtComKeyword4=night). These 4 words, if found and appear in richComResults, will be highlighted with color.</p> <p>I have no clue after searching for a while, my case is much different from other questions. I am a newbie in programming, your help would be much appreciated. Thank you!</p> <p>My Code:</p> <pre><code>private void searchComByKeywords() { // Process the list of files found in the directory. string[] fileEntries = Directory.GetFiles(sourceDir); 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 itemDescription = itemElement.GetElementsByTagName("description")[0].InnerText; if (txtComKeyword1.Text != (String.Empty) &amp;&amp; itemDescription.ToLower().Contains(txtComKeyword1.Text.ToLower()) || txtComKeyword2.Text != (String.Empty) &amp;&amp; itemDescription.ToLower().Contains(txtComKeyword2.Text.ToString()) || txtComKeyword3.Text != (String.Empty) &amp;&amp; itemDescription.ToLower().Contains(txtComKeyword3.Text.ToString()) || txtComKeyword4.Text != (String.Empty) &amp;&amp; itemDescription.ToLower().Contains(txtComKeyword4.Text.ToString())) { string itemTitle = itemElement.GetElementsByTagName("title")[0].InnerText; string itemDate = itemElement.GetElementsByTagName("pubDate")[0].InnerText; string itemAuthor = itemElement.GetElementsByTagName("author")[0].InnerText; richComResults.AppendText("Author: " + itemAuthor + "\nDate: " + itemDate + "\nTitle: " + itemTitle + "\nDescription: " + itemDescription + "\n\n--------\n\n"); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload