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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:47:37+00:00 2026-05-21T20:47:37+00:00

Hi i have some text which is meant to be displayed within a label.

  • 0

Hi i have some text which is meant to be displayed within a label.

“Hey @ronald and @tom where are we going this weekend”

What i need to do is change it to this instead

“Hey http://www.domain.com/ronald and http://www.domain.com/tom where are we going this weekend”

Now i have this code which someone off stackoverflow has helped me construct, however i am lost on what to do in the next step.

        Regex regex = new Regex(@"@[\S]+");
        MatchCollection matches = regex.Matches(strStatus);

        foreach (Match match in matches)
        {
            string Username = match.ToString().Replace("@", "");


        }

I cannot set the label in the foreach because it would disregard the last word replaced, i hope i am making sense.

  • 1 1 Answer
  • 2 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-21T20:47:38+00:00Added an answer on May 21, 2026 at 8:47 pm

    Keep the usernames you find in a list. Iterate over these from longest to shortest, replacing each occurrence of @[username] with http://www.domain.com/%5Busername%5D. The reason to do longest to shortest is to avoid replacing partial matches, as in “Hey, @tom and @tomboy …” This certainly isn’t the most efficient way to do the replacement (since you do a full string scan for each username, but given your example I suspect your strings are short and the lack of efficiency weighs less than the simplicity of this mechanism.

    var usernames = new List<string>();
    Regex regex = new Regex(@"@[\S]+");
    MatchCollection matches = regex.Matches(strStatus);
    
    foreach (Match match in matches)
    {
        usernames.Add( match.ToString().Replace("@", "") );
    }
    
    // do longest first to avoid partial matches
    foreach (var username in usernames.OrderByDescending( n => n.Length ))
    {
        strStatus = strStatus.Replace( "@" + username, "www.domain.com/" + username );
    }
    

    If you want to construct actual links it would look like:

    strStatus = strStatus.Replace( "@" + username,
                                   string.Format( "<a href='http://www.domain.com/{0}'>@{0}</a>", username ) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have some text which is separated by space@ .i displayed this array from
I have a div which has some text, but according to different situations this
I have some xml files that contain text, which are displayed on my website.
I have some text which I want to have on separate lines. I try
On my page in IE8, I have got some text which gets changed through
I have some text stored in a variable which contains some HTML. For example,
I have some text. Is there is any api which can tell me the
I have a edittext in which some text are selected . I want to
I have a text which contains hyperlinks, some hyperlinks contain spaces and I want
I have a JeditorPane which has some text in HTML format. When I execute

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.