Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:35:17+00:00 2026-06-09T23:35:17+00:00

The real Author name is : PolarBear. My function searched PolarBear , the result

  • 0

The real Author name is : PolarBear.

My function searched PolarBear, the result PolarBear was highlighted as I wished.

I searched Polarbear, polarbear and poLarbear, the PolarBear did appeared in result but was not highlighted as I wished.

How can I make the highlighting case insensitive like the search does? Thank you.

Highlighting Code:

    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;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:35:18+00:00Added an answer on June 9, 2026 at 11:35 pm

    You can try using an overload of the IndexOf method that uses a StringComparison enumeration.

    index = shadow.IndexOf(keyword, pointer,StringComparison.InvariantCultureIgnoreCase); 
    

    from second MSDN link:

    When you call a string comparison method such as String.Compare, String.Equals, or String.IndexOf, you should always call an overload that includes a parameter of type StringComparison so that you can specify the type of comparison that the method performs. For more information, see Best Practices for Using Strings in the .NET Framework.

    small working test example:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            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, StringComparison.InvariantCultureIgnoreCase);
                //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;
            } 
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Real noob question no doubt, but I can't get my head around this behaviour.
I need to print real datbase type name from DbParameter.DbType , but when I
A real F# noob question, but what is |> called and what does it
I've inherited a C# window's application that I'm not real crazy about. I've got
One limitation in Open Graph that it accepts only real-world objects like: Movie, Author,
I am trying to make a non interactive display for a real estate shop
I know how derived tables are used, but I still can’t really see any
Reading Real World Haskell, on page 95 the author provides an example: myFoldl f
I am new to CodeIgniter, but not new to PHP, and I was wondering
I feel my problem is quite obvious and has trivial solution, but I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.