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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:57:50+00:00 2026-05-13T17:57:50+00:00

I am bit new to c#, i am looking for a string matching pattern

  • 0

I am bit new to c#, i am looking for a string matching pattern to do the following,

I have a string like this

The book will be showcased at a
reception in Number 11 Downing Street
and will be attended by key healthcare

i need to create a span tag to highlight some text fragments using startIndex and length,

for an example,

  1. startIndex = 3, Length = 10
  2. startIndex = 8, Length = 8

i need to create a span tag dynamically and also create a separate span tag for intersections

in this case,

The < span id= 'span1' color='blue'> book < /span> < span id='intersectionSpan' color= pink > will </ span> < span id '= span2' color = 'yellow' > be showcased </ span>

anyone has come across any kinds of design pattern or smiler problems

please advice

  • 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-13T17:57:50+00:00Added an answer on May 13, 2026 at 5:57 pm

    I don’t think this related to desing pattern but i would look to what u asked as custom control

    as you know the label control will render as a span so start to make new control customlabel for example inherit it from the label control and creta functions inside it to accept the locations (startindex and length ) and the color (red , yellow )

    let’s say we have this function inside the control

     private string AddSpan(string originalString, int[] location, string color)
        {
            string old = originalString.Substring(location[0], location[1]);
            string newStr = string.Format("<span id= '{0}' color='{1}'>", "idUWant", color);
            originalString = originalString.Replace(old, newStr);
            return originalString ; 
        }
    

    the originaltext is The book will be showcased at a reception in Number 11 Downing Street
    and will be attended by key healthcare

    the location is simple 2 dimension array of integer the first one will be the start index and second one will be length , color parameter is color string

    i think it’s better to make data container for the paramters like a class holiding only a few properties like startindex and length and color to make it easier for reading and maintaining

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

Sidebar

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.