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 6210417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:09:19+00:00 2026-05-24T06:09:19+00:00

I have a dictionary collection that stores the starting position and the charecter values

  • 0

I have a dictionary collection that stores the starting position and the charecter values of a text file.

For example: a sample text file (a.txt) may contain text like “how are you? how do you do?”

I have indexed the above text as follows

Dictionary<long,string> charLocation = new Dictionary<long,string>(); 

charLocation[0] = "how" 
charLocation[1] = "ow" 
charLocation[2] = "w" 
charLocation[4] = "are" 
charLocation[6] = "e" 
charLocation[5] = "re" 
charLocation[11] = "?" 
charLocation[9] = "ou?" 
charLocation[10] = "u?" 
charLocation[8] = "you?" 
charLocation[13] = "how" 
charLocation[14] = "ow" 
charLocation[15] = "w" 
charLocation[17] = "do" 
charLocation[18] = "o" 
charLocation[21] = "ou" 
charLocation[22] = "u" 
charLocation[20] = "you" 
charLocation[26] = "?" 
charLocation[24] = "do?" 
charLocation[25] = "o?"

Now, I want to highlight each occurrence of “how” or “do” in the text file.

For this I want to first do a lookup in the dictionary collection and find each occurrence of the string, then open the text file and highlight the text for each occurrence.

How can i do this?

  • 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-05-24T06:09:21+00:00Added an answer on May 24, 2026 at 6:09 am

    Not tested, but this should works.

    public string HighLight (int startPoint, string text, string word)
    {
      if (startPoint > = 0)
      {
        int startIndex = text.indexOf (word, startPoint);
        if (startIndex >= 0)
        {
          StringBuilder builder = new StringBuilder ();
          builder.Append (text.Substring ( 0, startIndex));
          builder.Append ("<strong>");
          builder.Append (text.Substring (startIndex + 1, word.Length));
          builder.Append ("</strong>");
          builder.Append (text.Substring (startIndex + word.Length + 1));
          return HighLight ((startIndex + "<strong>".Length + "</strong>".Length + word.Length, builder.ToString (), word);
        }
      }
    
      //Word not found.
      return text;
    }
    

    So you could do :

    string myText = "how are you? how do you do?";
    string hightLightedText = HighLight (0, myText, "how");
    

    And if my code has no errors, that would returns “<strong>how</strong> are you? <strong>how</strong> do you do?”;

    Then you can repalce <strong> and </strong> with wathever you want to “highlight” your text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a Collection of some kind that itself contains Collections; e.g., Dictionary(Of
I have a Dictionary object in my ViewModel with key/values that translate words on
I have a Dictionary<int, string> which I want to take the Key collection into
A lot of the collection classes in .Net (i.e., List<T>, Dictionary<TKey, TValue>) have an
I have a dictionary of 200,000 items (the keys are strings and the values
I have a Dictionary<string, someobject> . EDIT: It was pointed out to me, that
I have a dictionary that I normally access with a key, so I need
I have a collection of physical parameters associated with different items. For example: Item,
I currently have a menu with subitems that is being stored in this dictionary
I have an ASP.Net app that retrieves a collection of roles for a given

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.