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

  • Home
  • SEARCH
  • 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 1085479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:41:40+00:00 2026-05-16T22:41:40+00:00

I have a string that could have any sentence in it but somewhere in

  • 0

I have a string that could have any sentence in it but somewhere in that string will be the @ symbol, followed by an attached word, sort of like @username you see on some sites.

so maybe the string is “hey how are you” or it’s “@john hey how are you”.

IF there’s an “@” in the string i want to pull what comes immediately after it into its own new string.

in this instance how can i pull “john” into a different string so i could theoretically notify this person of his new message? i’m trying to play with string.contains or .replace but i’m pretty new and having a hard time.

this btw is in c# asp.net

  • 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-16T22:41:41+00:00Added an answer on May 16, 2026 at 10:41 pm

    You should really learn regular expressions. This will work for you:

    using System.Text.RegularExpressions;
    
    var res = Regex.Match("hey @john how are you", @"@(\S+)");
    
    if (res.Success)
    {
        //john
        var name = res.Groups[1].Value;
    }
    

    Finds the first occurrence. If you want to find all you can use Regex.Matches. \S means anything else than a whitespace. This means it also make hey @john, how are you => john, and @john123 => john123 which may be wrong. Maybe [a-zA-Z] or similar would suit you better (depends on which characters the usernames is made of). If you would give more examples, I could tune it 🙂

    I can recommend this page:

    http://www.regular-expressions.info/

    and this tool where you can test your statements:

    http://regexlib.com/RESilverlight.aspx

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

Sidebar

Related Questions

I have a string that will look something like this: I'm sorry the code
If I have a string that contains Cat how could I check before hand
I have a string that has some Environment.Newline in it. I'd like to strip
I have a string that contains the representation of a date. It looks like:
I have a string that is like below. ,liger, unicorn, snipe in other languages
I have a string that looks like this: Name1=Value1;Name2=Value2;Name3=Value3 Is there a built-in class/function
I have a string that I would like to print . Is it possible
Let's say that I have string: -dog--cat--d-- I would like to find all words
Say I have a string that looks like this: str = The &yquick &cbrown
We have a string that we need to parse using regex, the string could

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.